即使我拒绝许可,此代码如何打开相机?
清单文件:
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
JAVA文件:
public void emojifyMe(View view) {
// Check for the external storage permission
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_CALENDAR)!=PackageManager.PERMISSION_GRANTED) {
// If you do not have permission, request it
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_CALENDAR},1 );
} else {
// Launch the camera if the permission exists
launchCamera();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
// Called when you request permission to read and write to external storage
switch (requestCode) {
case 1: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// If you get permission, launch the camera
launchCamera();
} else {
// If you do not get permission, show a Toast
Toast.makeText(this, R.string.permission_denied, Toast.LENGTH_SHORT).show();
launchCamera();
//*** But see here I am getting my work done here then whats this Runtime Permission exactly??
}
break;
}
}
}
它会打开相机但不应该由于权限被拒绝。可能的原因是什么?