if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M) { var permission = Permission.ReadExternalStorage; if (ContextCompat.CheckSelfPermission(this, permission) != Android.Content.PM.Permission.Granted) { ActivityCompat.RequestPermissions(this, new String[] { permission }, 1); } }
一次申请多个授权
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M) { var permission = new string[] { Permission.ReadExternalStorage, Permission.WriteExternalStorage, Permission.Camera }; var requestPermissions = permission.Where(p => ContextCompat.CheckSelfPermission(this, p) != Android.Content.PM.Permission.Granted).ToList(); if (requestPermissions.Count >0 ) ActivityCompat.RequestPermissions(this, requestPermissions.ToArray(), 1); var unauthorizedPermissions = permission.Where(p => ContextCompat.CheckSelfPermission(this, p) != Android.Content.PM.Permission.Granted).ToList(); if (unauthorizedPermissions.Count > 0) { Toast.MakeText(this, "部分授权未被允许", ToastLength.Long).Show(); return; } }