I had problems with the manual process for permission requests (I just kept getting into the "denied" code), so I switched to using Dexter for simplification. I applied the following code in onCreate (), and I did a fresh install of the application:
Dexter.withActivity(this) .withPermission(Manifest.permission.CAMERA) .withListener(new PermissionListener() { @Override public void onPermissionGranted(PermissionGrantedResponse response) { Log.d(TAG, "GRANTED!"); initCamera(); } @Override public void onPermissionDenied(PermissionDeniedResponse response) { Log.d(TAG, "DENIED!"); } @Override public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) { Log.d(TAG, "PERMISSION RATIONAL SHOULD BE SHOWN!"); } }).check();
He immediately gets into "DENIED!" magazine, and he doesn't even tell me. I tried this specific code to try a few permissions (which ultimately needs to be done):
Dexter.withActivity(activity) .withPermissions(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE) .withListener(new MultiplePermissionsListener() { @Override public void onPermissionsChecked(MultiplePermissionsReport report) { Log.d(TAG, "Accepted: " + report.getGrantedPermissionResponses().size() + " | Denied: " + report.getDeniedPermissionResponses().get(0).getPermissionName()); } @Override public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) { Log.d(TAG, "continuing permissions request.."); token.continuePermissionRequest(); } }) .check();
He asks for permission to record audio, then asks about access to photos / multimedia / files on the device (he never asks about the Camera). Then, after that, he prints the magazine: "Accepted 3 | Denied: android.permission.CAMERA". He denies this without even forcing me again.
My manifest is set correctly so that CAMERA is in the right place (outside the "app" tag). See below for reference:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my.app"> <uses-feature android:name="android.hardware.camera" android:required="true" /> <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> etc..
The fuzzy thing is that when I go to Settings> Applications> MyApp, the Camera option doesn't even appear there.
I don't think this is a problem with Dexter, as it does basically the same thing when I manually configured it (and I confirmed that it is definitely configured correctly in this case by looking at a few top SO posts).
Any thoughts on what the problem might be here? FYI - I am using Galaxy S6, OS 6.0.2. Other users experiencing this seem to be other devices with OS 6.0+. Thanks in advance!
EDIT: Testing various devices, it works on some and doesn't work on some:
- Moto X (OS 5.0) - Broken
- Nexus 5 (OS 7.0) - works
- Samsung S6 (OS 6.0.1) - Broken
- Broken Moto X (OS 6.0) - works
This does not seem to be a solid drawing. Definitely weird. I also started a new project and ran the same code - it worked fine and allowed access to my camera. Thus, it does not look completely device specific.