ActivityCompat.requestPermissions not showing dialog box

前端 未结 20 1448
野趣味
野趣味 2020-12-07 17:15
if (ContextCompat.checkSelfPermission(RegisterActivity.this,      Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_DENIED){
            ActivityCom         


        
相关标签:
20条回答
  • 2020-12-07 17:57

    Don't forget to write the permissions without extra spaces in the manifest. In my case i had:

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

    But look, at the end, there's an extra space. Just write it the right way

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

    And it's working now

    0 讨论(0)
  • 2020-12-07 17:58

    I had a need to request permission for WRITE_EXTERNAL_STORAGE but was not getting a pop-up despite trying all of the different suggestions mentioned.

    The culprit in the end was HockeyApp. It uses manifest merging to include its own permission for WRITE_EXTERNAL_STORAGE except it applies a max sdk version onto it.

    The way to get around this problem is to include it in your Manifest file but with a replace against it, to override the HockeyApp's version and success!

    4.7.2 Other dependencies requesting the external storage permission (SDK version 5.0.0 and later) To be ready for Android O, HockeySDK-Android 5.0.0 and later limit the WRITE_EXTERNAL_STORAGE permission with the maxSdkVersion filter. In some use cases, e.g. where an app contains a dependency that requires this permission, maxSdkVersion makes it impossible for those dependencies to grant or request the permission. The solution for those cases is as follows:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace"/>
    

    It will cause that other attributes from low priority manifests will be replaced instead of being merged.

    https://support.hockeyapp.net/kb/client-integration-android/hockeyapp-for-android-sdk#permissions-advanced

    0 讨论(0)
  • 2020-12-07 17:58

    I was having the same problem, and solved it by replacing Manifest.permission.READ_PHONE_STATE with android.Manifest.permission.READ_PHONE_STATE.

    0 讨论(0)
  • 2020-12-07 17:58

    I came across this problem in Samsung S8 and N8 (havent found in any other)

    so the problem is in the manifest file uses-permission

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

    For some reason, the attribute android:requiredFeature is the culprit. and I haven't found the explanation on why.

    to solve simply remove it,

    <uses-permission android:name="android.permission.CAMERA" />
    
    0 讨论(0)
  • 2020-12-07 17:59

    it happen to me i was running it on API 23 and i had to use the code to request permission like this code below put it on on create method. note that MY_PERMISSIONS_REQUEST_READ_LOCATION is an integer that is equal to 1 example int MY_PERMISSIONS_REQUEST_READ_LOCATION = 1:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { requestPermissions(new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION},MY_PERMISSIONS_REQUEST_READ_LOCATION); }

    0 讨论(0)
  • 2020-12-07 18:00

    It could be not a problem with a single line of your code.

    On some devices (I don't recall if it is in stock Android) the Permission dialog includes a check box labeled "Never ask again". If you click Deny with the box checked then you won't be prompted again for that permission, it will automatically be denied to the app. To rever this, you have to go into Settings -> App -> Permissions and re--enable that perm for the app. Then turn it off to deny it again. You may have to open the app before turning it off again, not sure.

    I don't know if your Nexus has it. Maybe worth a try.

    0 讨论(0)
提交回复
热议问题