我有一个 android 应用程序,当用户单击相机图标时,我会在其中请求许可。我也想要外部存储
以下是我的代码
private boolean isCameraPermissionGranted() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
requestPermissions(new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
return false;
}
}
return false;
}
public boolean isStoragePermissionGranted() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.v("","Permission is granted");
return true;
} else {
Log.v("","Permission is revoked");
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_STORAGE_PERMISSION);
return false;
}
}
else { //permission is automatically granted on sdk<23 upon installation
Log.v("","Permission is granted");
return true;
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_CAMERA_PERMISSION:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
takePicture();
}
break;
default:
break;
}
}
问题是当用户拒绝许可时,应用程序会卡在白页上。
当用户拒绝权限时,如何导航回以前的活动。