• 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
Oct 3, 2017
5
0
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:
  • Like
Reactions: codesplice
Upvote 0
@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.
 
Upvote 0
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.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones