Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

revoked permission android.permission.CAMERA

Tags:

android

I get ERROR revoked permission android.permission.CAMERA

I was using camera permission on manifest

private void dispatchTakePictureIntent(int actionCode) {      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);      switch (actionCode) {         case ACTION_TAKE_PHOTO_B:             File f = null;              try {                 f = setUpPhotoFile();                 mCurrentPhotoPath = f.getAbsolutePath();                 takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));             } catch (IOException e) {                 e.printStackTrace();                 f = null;                 mCurrentPhotoPath = null;             }             break;          default:             break;     } // switch      startActivityForResult(takePictureIntent, actionCode); } 

and error like this:

E/AndroidRuntime: FATAL EXCEPTION: main                    Process: com.mobile.lunatique.photo, PID: 3590                    java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera2/com.android.camera.CaptureActivity clip={text/uri-list U:file:///KTP_42342.jpg} (has extras) } from ProcessRecord{2fbbd91 3590:com.mobile.lunatique.photo/u0a60} (pid=3590, uid=10060) with revoked permission android.permission.CAMERA                        at android.os.Parcel.readException(Parcel.java:1599)                        at android.os.Parcel.readException(Parcel.java:1552)                        at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2658)                        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)                        at android.app.Activity.startActivityForResult(Activity.java:3917)                        at android.app.Activity.startActivityForResult(Activity.java:3877)                        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)                        at com.mobile.lunatique.photo.MainActivity.dispatchTakePictureIntent(MainActivity.java:254)                        at com.mobile.lunatique.photo.MainActivity.access$000(MainActivity.java:33)                        at com.mobile.lunatique.photo.MainActivity$1.onClick(MainActivity.java:321)                        at android.view.View.performClick(View.java:5198)                        at android.view.View$PerformClick.run(View.java:21147)                        at android.os.Handler.handleCallback(Handler.java:739)                        at android.os.Handler.dispatchMessage(Handler.java:95)                        at android.os.Looper.loop(Looper.java:148)                        at android.app.ActivityThread.main(ActivityThread.java:5417)                        at java.lang.reflect.Method.invoke(Native Method)                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  I/Process: Sending signal. PID: 3590 SIG: 9

anyone can help me??

like image 406
lunatique aldebaran Avatar asked Mar 27 '17 09:03

lunatique aldebaran


People also ask

How do I open camera permission?

Enable camera on an Android deviceOpen the “Settings” app. Tap “Apps & notifications”. Tap “Merge Explorer” or “Object Viewer” (both need permission). Tap “Permissions”, then choose the “Camera” permission to enable.

How do I give camera permission in Android 11?

Starting in Android 11, whenever your app requests a permission related to location, microphone, or camera, the user-facing permissions dialog contains an option called Only this time. If the user selects this option in the dialog, your app is granted a temporary one-time permission.

What is READ_PHONE_STATE permission?

READ_PHONE_STATE is one of the Android permissions categorized as dangerous. This is because it “allows read only access to phone state, including the phone number of the device, current cellular network information, the status of any ongoing calls, and a list of any Phone Accounts registered on the device” [2] .


1 Answers

Here's how I solved this problem.

Contrary to what most answers say, REMOVE this from your Manifest file.

 <uses-permission android:name="android.permission.CAMERA"/> 

Why?

Starting Android M (API 23), if your app has CAMERA permission declared in the manifest, then, it needs that CAMERA permission to be GRANTED in order to access ACTION_IMAGE_CAPTURE etc... too (which normally do not require the CAMERA permission on their own). If not, then it automatically raises a SecurityException.

╔═════════════════════════════════════════════════╦════════════════════╗ ║                      Usage                      ║ Permissions needed ║ ╠═════════════════════════════════════════════════╬════════════════════╣ ║ ACTION_IMAGE_CAPTURE                            ║ none               ║ ║ ACTION_VIDEO_CAPTURE                            ║ none               ║ ║ INTENT_ACTION_STILL_IMAGE_CAMERA                ║ none               ║ ║ android.hardware.camera2                        ║ CAMERA             ║ ║ android.hardware.camera2 + ACTION_IMAGE_CAPTURE ║ CAMERA             ║ ║ android.hardware.camera2 + ACTION_VIDEO_CAPTURE ║ CAMERA             ║ ║ ...                                             ║ ...                ║ ╚═════════════════════════════════════════════════╩════════════════════╝ 

Above table is only for API 23+

tl;dr What to do?

Option 1- If you only use ACTION_IMAGE_CAPTURE etc...
Remove the CAMERA permission from manifest and you would be fine

Option 2- If you use other CAMERA functions:
Check for CAMERA permission at runtime and only start the intent when the permission is available

like image 62
Kathir Avatar answered Sep 20 '22 17:09

Kathir