1. Download our Official Android App: Forums for Android!

Permission popup doesn't show on Android 7.0

Discussion in 'Android Development' started by Kazuwa, Oct 3, 2017.

  1. Kazuwa

    Kazuwa Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Oct 3, 2017

    Oct 3, 2017
    5
    0
    5
    Hi,

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

    Code (Java):
    1. int permission = PermissionChecker.checkSelfPermission(getReactApplicationContext(), Manifest.permission.CAMERA);
    2.  
    3. if (permission != PackageManager.PERMISSION_GRANTED) {
    4.       ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.CAMERA}, PERMISSION_REQUEST_CAMERA);
    5. }
    6.  
    7. 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 :

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

    Thanks for your answer,
     

    Advertisement

    #1 Kazuwa, Oct 3, 2017
    Last edited by a moderator: Oct 3, 2017
  2. steve

    steve Developer
    Administrator
    Rank:
    None
    Points:
    573
    Posts:
    1,086
    Joined:
    Apr 19, 2011

    Apr 19, 2011
    1,086
    1,178
    573
    Male
    Android Developer
    York, PA
    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

    Code (Java):
    1.  
    2. requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_REQUEST_CODE);
    3.  
     
    #2 steve, Oct 3, 2017
    Last edited: Oct 3, 2017
    codesplice likes this.
  3. Kazuwa

    Kazuwa Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Oct 3, 2017

    Oct 3, 2017
    5
    0
    5
    Yes, I am using requestPermissions, that's the function that doesn't work for me on Android 7.0
     
  4. steve

    steve Developer
    Administrator
    Rank:
    None
    Points:
    573
    Posts:
    1,086
    Joined:
    Apr 19, 2011

    Apr 19, 2011
    1,086
    1,178
    573
    Male
    Android Developer
    York, PA
    Oh, sorry. I misread. Have you tested more that one 7.0 device?
     
  5. Kazuwa

    Kazuwa Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Oct 3, 2017

    Oct 3, 2017
    5
    0
    5
    Yes, on Google Pixel and Nexus 6
     
  6. steve

    steve Developer
    Administrator
    Rank:
    None
    Points:
    573
    Posts:
    1,086
    Joined:
    Apr 19, 2011

    Apr 19, 2011
    1,086
    1,178
    573
    Male
    Android Developer
    York, PA
    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.
     
  7. Unforgiven

    Unforgiven I didn't know there were cacti in Aruba.
    Moderator
    Rank:
     #1
    Points:
    4,238
    Posts:
    37,064
    Joined:
    Jun 23, 2010

    Jun 23, 2010
    37,064
    44,517
    4,238
    Male
    Douglas, MA
    Development thread moved to the dev area for better exposure. :)

    @steve is as good as it gets, so good luck. :)
     
    steve likes this.
  8. Kazuwa

    Kazuwa Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Oct 3, 2017

    Oct 3, 2017
    5
    0
    5
    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.
     
  9. steve

    steve Developer
    Administrator
    Rank:
    None
    Points:
    573
    Posts:
    1,086
    Joined:
    Apr 19, 2011

    Apr 19, 2011
    1,086
    1,178
    573
    Male
    Android Developer
    York, PA
    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.
     
    Unforgiven likes this.
  10. steve

    steve Developer
    Administrator
    Rank:
    None
    Points:
    573
    Posts:
    1,086
    Joined:
    Apr 19, 2011

    Apr 19, 2011
    1,086
    1,178
    573
    Male
    Android Developer
    York, PA
    @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:

    Code (Java):
    1.  
    2. boolean hasPermission = (ContextCompat.checkSelfPermission(
    3.     NewPostActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) ==
    4.     PackageManager.PERMISSION_GRANTED);
    5.  
    6. if (!hasPermission) {
    7.   if (!fromPermissionsResult) {
    8.     ActivityCompat.requestPermissions(
    9.         NewPostActivity.this,
    10.         new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},
    11.         BaseActivity.REQUEST_WRITE_STORAGE_CAMERA);
    12.   }
    13. } else {
    14.   camSnapCount++;
    15.   File output = new File(
    16.       new File(getFilesDir(), "images/"), CAM_FILENAME + "_" + camSnapCount + ".jpeg");
    17.  
    18.   if (output.exists()) {
    19.     output.delete();
    20.   } else {
    21.     output.getParentFile().mkdirs();
    22.   }
    23.  
    24.   Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    25.   Uri outputUri = FileProvider.getUriForFile(NewPostActivity.this, AUTHORITY, output);
    26.   intent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
    27.  
    28.   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    29.     intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    30.   } else {
    31.     ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri);
    32.     intent.setClipData(clip);
    33.     intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    34.   }
    35.  
    36.   startActivityForResult(intent, IMAGE_REQUEST_CODE);
    37. }
    38.  
    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.
     
  11. Kazuwa

    Kazuwa Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Oct 3, 2017

    Oct 3, 2017
    5
    0
    5
    I use the AndroidManifest.xml

    Code (Java):
    1. <uses-permission android:name="android.permission.CAMERA"/>
    And the java method which communicate with react native :

    Code (Java):
    1. @ReactMethod
    2. public void getPermission(String permissionType, Promise promise) {
    3.     if (permissionType.equals("camera")) {
    4.         int permission = PermissionChecker.checkSelfPermission(getReactApplicationContext(), Manifest.permission.CAMERA);
    5.  
    6.         System.out.println("JULOGS=shouldShowRequestPermissionRationale: " + ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA));
    7.  
    8.         if (permission != PackageManager.PERMISSION_GRANTED) {
    9.             ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.CAMERA}, PERMISSION_REQUEST_CAMERA);
    10.         }
    11.  
    12.         promise.resolve(permission);
    13.     } else if (permissionType.equals("photoLibrary")) {
    14.         int permission = PermissionChecker.checkSelfPermission(getReactApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
    15.  
    16.         if (permission != PackageManager.PERMISSION_GRANTED) {
    17.             ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
    18.         }
    19.  
    20.         promise.resolve(permission);
    21.     }
    22. }
    And then when, the permission is OK, I open the camera from react native.
     
  12. steve

    steve Developer
    Administrator
    Rank:
    None
    Points:
    573
    Posts:
    1,086
    Joined:
    Apr 19, 2011

    Apr 19, 2011
    1,086
    1,178
    573
    Male
    Android Developer
    York, PA
    Could very well be a bug in the Android lib, Android is or in the React annotation generated code.

    I did see this... which could also explain the behavior you are seeing: https://stackoverflow.com/a/40639430/468360

    If you do find a solution, be sure to help others out by posting how you fixed it.

    Good luck!
     
    Unforgiven likes this.

Share This Page

Loading...