Android: Permission Denial: starting Intent with revoked permission android.permission.CAMERA
Solution 1
Remove this permission
<uses-permission android:name="android.permission.CAMERA"/>
I faced this error executing my app in android 7. After tests I noticed user permission wasn't in project A but it was in project B, that I only tested in android 5 devices. So I remove that permission in project B in order to run it on other device that targets android 7 and it finally could open.
In adittion I added the fileprovider code that Android suggests here https://developer.android.com/training/camera/photobasics.html Hope this helps.
Solution 2
hi you can use these permission in your manifest file with other permission,
<uses-feature
android:name="android.hardware.camera.any"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
If still it not working then may be you are using android M,SO you need to programmatically add permissions.
here is example
hi here is few steps for setup permission for android M and remember you should declare same permission in manifest file as well.
Step 1. Declare global variable :
public final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 1;
//requests for runtime time permissions
String CAMERA_PERMISSION = android.Manifest.permission.CAMERA;
String READ_EXTERNAL_STORAGE_PERMISSION = android.Manifest.permission.READ_EXTERNAL_STORAGE;
String WRITE_EXTERNAL_STORAGE_PERMISSION = android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
// for security permissions
@DialogType
private int mDialogType;
private String mRequestPermissions = "We are requesting the camera and Gallery permission as it is absolutely necessary for the app to perform it\'s functionality.\nPlease select \"Grant Permission\" to try again and \"Cancel \" to exit the application.";
private String mRequsetSettings = "You have rejected the camera and Gallery permission for the application. As it is absolutely necessary for the app to perform you need to enable it in the settings of your device.\nPlease select \"Go to settings\" to go to application settings in your device and \"Cancel \" to exit the application.";
private String mGrantPermissions = "Grant Permissions";
private String mCancel = "Cancel";
private String mGoToSettings = "Go To Settings";
private String mPermissionRejectWarning = "Cannot Proceed Without Permissions</string>
<string name="explanation_permission_location_request">We are requesting the location permission as it is necessary for the app to perform search functionality properly.\nPlease select \"Grant Permission\" to try again and \"Cancel \" to deny permission.";
// create dialog like this.
// type of dialog opened in MainActivity
@IntDef({DialogType.DIALOG_DENY, DialogType.DIALOG_NEVER_ASK})
@Retention(RetentionPolicy.SOURCE)
@interface DialogType {
int DIALOG_DENY = 0, DIALOG_NEVER_ASK = 1;
}
Step 2. Use this code in your main activity
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED && grantResults[2] == PackageManager.PERMISSION_GRANTED) {
// Call your camera here.
} else {
boolean showRationale1 = shouldShowRequestPermissionRationale(CAMERA_PERMISSION);
boolean showRationale2 = shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE_PERMISSION);
boolean showRationale3 = shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE_PERMISSION);
if (showRationale1 && showRationale2 && showRationale3) {
//explain to user why we need the permissions
mDialogType = ValueConstants.DialogType.DIALOG_DENY;
// Show dialog with
openAlertDialog(mRequestPermissions, mGrantPermissions, mCancel, this, MyActivity.this);
} else {
//explain to user why we need the permissions and ask him to go to settings to enable it
mDialogType = ValueConstants.DialogType.DIALOG_NEVER_ASK;
openAlertDialog(mRequsetSettings, mGoToSettings, mCancel, this, MyActivity.this);
}
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
//check for camera and storage access permissions
@TargetApi(Build.VERSION_CODES.M)
private void checkMultiplePermissions(int permissionCode, Context context) {
String[] PERMISSIONS = {CAMERA_PERMISSION, READ_EXTERNAL_STORAGE_PERMISSION, WRITE_EXTERNAL_STORAGE_PERMISSION};
if (!hasPermissions(context, PERMISSIONS)) {
ActivityCompat.requestPermissions((Activity) context, PERMISSIONS, permissionCode);
} else {
// Open your camera here.
}
}
private boolean hasPermissions(Context context, String... permissions) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
Step 3. Call this method in your oncreate method,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkMultiplePermissions(REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS, MyActivity.this);
} else {
// Open your camera here.
}
Step 4. Dialog for permission deny
public static void openAlertDialog(String message, String positiveBtnText, String negativeBtnText,
final OnDialogButtonClickListener listener,Context mContext) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.AlertDialogCustom);
builder.setPositiveButton(positiveBtnText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
listener.onPositiveButtonClicked();
}
});
builder.setPositiveButton(positiveBtnText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
listener.onNegativeButtonClicked();
}
});
builder.setTitle(mContext.getResources().getString(R.string.app_name));
builder.setMessage(message);
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setCancelable(false);
builder.create().show();
}
// Create this interface
public interface OnDialogButtonClickListener {
void onPositiveButtonClicked();
void onNegativeButtonClicked();
}
and implement this in your activity where need to add permissions.
@Override
public void onPositiveButtonClicked() {
switch (mDialogType) {
case ValueConstants.DialogType.DIALOG_DENY:
checkMultiplePermissions(REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS, MyActivity.this);
break;
case ValueConstants.DialogType.DIALOG_NEVER_ASK:
redirectToAppSettings(MyActivity.this);
break;
}
}
@Override
public void onNegativeButtonClicked() {
}
And anyone permission you can call from here and every result you can get in override method onRequestPermissionsResult this one.
UPDATE :
Now we have very sorted way for permission handling. So,here is the steps. I have added here for kotlin.
Step 1. Declare this as global variable or any where.
private val permissions = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { granted ->
granted.entries.forEach {
when (it.value) {
true -> {
// Call whatever you want to do when someone allow the permission.
}
false -> {
showPermissionSettingsAlert(requireContext())
}
}
}
}
Step 2.
// You can put this line in constant.
val storagePermission = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE
)
// You can put this in AppUtil.
fun checkPermissionStorage(context: Context): Boolean {
val result =
ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)
return result == PackageManager.PERMISSION_GRANTED
}
// Put this where you need Permission check.
if (!checkPermissionStorage(requireContext())) {
permissions.launch(
storagePermission
)
} else {
// Permission is already added.
}
Step 3. Permission rejection Dialog. If you want you can use this.
fun showPermissionSettingsAlert(context: Context) {
val builder = AlertDialog.Builder(context)
builder.setTitle("Grant Permission")
builder.setMessage("You have rejected the Storage permission for the application. As it is absolutely necessary for the app to perform you need to enable it in the settings of your device. Please select \"Go to settings\" to go to application settings in your device.")
builder.setPositiveButton("Allow") { dialog, which ->
val intent = Intent()
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
val uri = Uri.fromParts("package", context.packageName, null)
intent.data = uri
context.startActivity(intent)
}
builder.setNeutralButton("Deny") { dialog, which ->
dialog.dismiss()
}
val dialog = builder.create()
dialog.show()
}
Thankyou
hope this will help you (Y).
Solution 3
Here is how I solved mine:
First of all I think the issue arises when you try to use your device Camera on (SDK < 26) without FULL permissions.
Yes, even though you have already included this permission:
<uses-permission android:name="android.permission.CAMERA"/>
To solve this issue I changed that to this:
<uses-permission android:name="android.permission.CAMERA"
android:required="true"
android:requiredFeature="true"/>
This information from the Android Docs, might be really helpful
If your application uses, but does not require a camera in order to function, instead set
android:required
tofalse
. In doing so, Google Play will allow devices without a camera to download your application. It's then your responsibility to check for the availability of the camera at runtime by callinghasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
. If a camera is not available, you should then disable your camera features.
Solution 4
In my case the problem was related to my emulator permissions ,
To fix the issue :
1- Go to Settings of your emulator.
2- Look for Apps and Notifications.
3- Click on Add Permission.
see the pic : https://i.stack.imgur.com/z4GfK.png
4- Select Camera of the list.
5- Look for your Application in the provided list.
6- Enable Camera.
see the pic : https://i.stack.imgur.com/dJ8wG.pngEnjoy
Now you can use your camera on your emulator :)
Solution 5
private String [] permissions = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.ACCESS_FINE_LOCATION", "android.permission.READ_PHONE_STATE", "android.permission.SYSTEM_ALERT_WINDOW","android.permission.CAMERA"};
on your OnCreate
add this:
int requestCode = 200;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(permissions, requestCode);
}
Related videos on Youtube
David Faizulaev
Updated on April 02, 2022Comments
-
David Faizulaev about 2 years
I'm trying to start a ACTION_IMAGE_CAPTURE activity in order to take a picture in my app and I'm getting the error in the subject.
Stacktrace:
FATAL EXCEPTION: main Process: il.ac.shenkar.david.todolistex2, PID: 3293 java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE cmp=com.google.android.GoogleCamera/com.android.camera.CaptureActivity } from ProcessRecord{22b0eb2 3293:il.ac.shenkar.david.todolistex2/u0a126} (pid=3293, uid=10126) with revoked permission android.permission.CAMERA
The camera permissions is added to the manifest.xml fie:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-permission android:name="android.permission.WRITE_CALENDAR" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.CAMERA" />
Here is the call to open the camera:
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.statusgroup); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { RadioButton rb = (RadioButton) findViewById(R.id.donestatusRBtn); if(rb.isChecked()) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } } } });
-
Doug Stevenson over 8 yearsPossible duplicate of Android M Camera Intent + permission bug?
-
David Faizulaev over 8 years@DougStevenson, It's a Nexus 5, does it occur on this device?
-
Doug Stevenson over 8 yearsIt's not about the device, it's about changes made in Android M. If the reference question doesn't help you, feel free to ignore it.
-
-
David Faizulaev over 8 yearsThe call to the camera in not in the main activity, should I still place the methods in the main activity?
-
Saveen over 8 yearsYes, you can call this permission in first activity.
-
David Faizulaev over 8 yearsTried it, did not help.
-
Saveen over 8 yearscan you try it once stackoverflow.com/questions/26377171/…
-
Saveen over 8 yearsthis exception is only for Android M, Just pass proper camera permission and whenever application start one popup will appear need to do yes,then you'll get permission to use camera things in your app.
-
David Faizulaev over 8 yearsStill get the exception.
-
Saveen over 8 yearsAre you kidding me, I just made same example and it's working fine here is link dropbox.com/s/w29sljy0zpwwm61/MyApplication.zip?dl=0
-
Saveen over 8 yearsI have tested in Nexus 5 with Android M
-
Saveen over 8 yearsLet us continue this discussion in chat.
-
sai over 6 yearsStrange how removing the permission, actually removed the error for requiring permission!!!!
-
MrX over 6 yearsIts work on Android N, but use @Saveen first answer as permission on your manifest. Tested by me
-
Yahya over 6 yearsPlus one from me, your answer is the only one that worked for me.. It's weird though!
-
IgniteCoders about 6 yearsThis is not what the question is looking for. This line should be added to the Manifest if you are using the Camera inside your app, not calling other Camera App and wait for a result.
-
Dan Anderson over 5 yearsThis is the most up to date answer that works with the "dangerous permissions" release on v6 (marshmallow)
-
Ankit Dubey over 4 yearsOMG! seriously It is working. Although from starting phase of development I was to add this line in menifest.
-
Arnold Brown over 4 yearsBut my app has both like call Camera through Intent and also like inbuilt camera. Giving permission make working Inbuilt and without permission Intent camera is working
-
Eddie about 4 yearsStrange, but it worked for me too.. However in my case I removed that and replaced it with <uses-feature android:name="android.hardware.camera" android:required="false" />
-
paulsm4 over 3 yearsWorked for me :)
-
Диана Ганеева about 2 yearsit doesn't work, but it seems like requesting permission as usual works
-
Yogesh Seralia about 2 years@ArnoldBrown so did you replaced intent fire with your custom camera impl. to cater this issue? I am also facing the same case.