• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Permission popup doesn't show on Android 7.0

Kazuwa

Lurker
Hi,

I have a react native app, I use this java code to check the camera permission :

Java:
int permission = PermissionChecker.checkSelfPermission(getReactApplicationContext(), Manifest.permission.CAMERA);

if (permission != PackageManager.PERMISSION_GRANTED) {
      ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.CAMERA}, PERMISSION_REQUEST_CAMERA);
}

promise.resolve(permission);

On Android 6.0, when the camera permission is off, the native permission popup shows thanks to the requestPermissions function.

However, it doesn't show on Android 7.0.

I checked the result of :

Java:
ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA)
It's false on Android 6.0 and 7.0

Thanks for your answer,
 
Last edited by a moderator:
Hi,

I have a react native app, I use this java code to check the camera permission :

int permission = PermissionChecker.checkSelfPermission(getReactApplicationContext(), Manifest.permission.CAMERA);

if (permission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.CAMERA}, PERMISSION_REQUEST_CAMERA);
}

promise.resolve(permission);

On Android 6.0, when the camera permission is off, the native permission popup shows thanks to the requestPermissions function.

However, it doesn't show on Android 7.0.

I checked the result of :

ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA)
It's false on Android 6.0 and 7.0

Thanks for your answer,

You need to use requestPermissions ...you are just checking the manifest, which doesn't even matter for the new permission request setup.

Click here for docs

Java:
requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_REQUEST_CODE);
 
Last edited:
Yes, on Google Pixel and Nexus 6

I'll double check some code when I can but I don't think I'll add much... pretty straight forward.

Maybe try a different support lib version? ...could be a bug.
 
It seems like a bug. For example, when I use a Android 6.0 device, the result of shouldShowRequestPermissionRationale is false but the popup still shows.
 
Idea! Test the Forums app out on the same devices it doesn't work... if it works, I'll get you the code when I can... If not, I'll research the bug 😁

Oh, to fully test use the camera icon in the new post window. Pretty sure you should rate the app 5 stars too just to be safe.
 
@Kazuwa - I totally forgot about this but there are two ways to use the camera. I guess what is the end result of what you are trying to do?

In Forums for Android (this sites Android app), I do not use the Manifest.permission.CAMERA at all. What I do is something more like this:

Java:
boolean hasPermission = (ContextCompat.checkSelfPermission(
    NewPostActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) ==
    PackageManager.PERMISSION_GRANTED);

if (!hasPermission) {
  if (!fromPermissionsResult) {
    ActivityCompat.requestPermissions(
        NewPostActivity.this,
        new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},
        BaseActivity.REQUEST_WRITE_STORAGE_CAMERA);
  }
} else {
  camSnapCount++;
  File output = new File(
      new File(getFilesDir(), "images/"), CAM_FILENAME + "_" + camSnapCount + ".jpeg");

  if (output.exists()) {
    output.delete();
  } else {
    output.getParentFile().mkdirs();
  }

  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  Uri outputUri = FileProvider.getUriForFile(NewPostActivity.this, AUTHORITY, output);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  } else {
    ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri);
    intent.setClipData(clip);
    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  }

  startActivityForResult(intent, IMAGE_REQUEST_CODE);
}

For that code above to work, you will need to set up the proper AUTHORITY, which could be a separate question on its own. If you are using the camera, and need specific features... then I can set up a test for that to see whats up. I just want to confirm what you are doing first.
 
I use the AndroidManifest.xml

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

And the java method which communicate with react native :

Java:
@ReactMethod
public void getPermission(String permissionType, Promise promise) {
    if (permissionType.equals("camera")) {
        int permission = PermissionChecker.checkSelfPermission(getReactApplicationContext(), Manifest.permission.CAMERA);

        System.out.println("JULOGS=shouldShowRequestPermissionRationale: " + ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA));

        if (permission != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.CAMERA}, PERMISSION_REQUEST_CAMERA);
        }

        promise.resolve(permission);
    } else if (permissionType.equals("photoLibrary")) {
        int permission = PermissionChecker.checkSelfPermission(getReactApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE);

        if (permission != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
        }

        promise.resolve(permission);
    }
}

And then when, the permission is OK, I open the camera from react native.
 
Back
Top Bottom