Android Camera permissions are prohibited without a hint.

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.

+8
android android-externalstorage android-camera
source share
2 answers

The problem with this turned out to be a third-party library that had this line in its manifest, overriding our own permission:

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

The solution was either to manually import your project as a module (rather than using gradle) and then comment on this line, or simpler - you can add "tools: node =" replace "" to the end of the main CAMERA resolution line of the project , and after that it works great; There is no need to import the project using the latter approach.

+11
source share

What you need is permissions for the runtime that are not executed since Android 6.0 (API level 23), users provide permissions for applications while the application is running, and not when installing the application. This approach simplifies the installation process of the application because the user does not need to grant permissions when installing or updating the application. It also gives the user more control over the functionality of the application; for example, the user may choose to access the camera for the camera, but not to the location of the device. The user can revoke permissions at any time by going to the application settings screen.

// Assume thisActivity is the current activity int permissionCheck = ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.YOUR_PERMISSION);

then you need to request a specific permission if this check is incorrect,

  ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.YOUR_PERMISSION}, MY_PERMISSION_CODE); 

At the same time, you also need to declare them also in the manifest, based on the fact that you have already shown what has already been done. For more information .

+1
source share