ActivityCompat.requestPermissions not showing dialog box

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


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

    No matter what you do, Check if you declare Permission you need in the Manifest file.

    
        <!--Declaring the required permissions-->
        <uses-permission
            android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <uses-permission
            android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission
            android:name="android.permission.CAMERA" />
    
    
    

    Then go to next steps..

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

    I had the same issue and it turned out to be due to the manifest merger tool pulling in an android:maxSdkVersion attribute from a dependency.

    To view the actual permissions you're requesting in your APK you can use the aapt tool, like this:

    /path/to/android-sdk/build-tools/version/aapt d permissions /path/to/your-apk.apk
    

    in my case, it printed:

    uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE' maxSdkVersion='18'
    

    even though I hadn't specified a maxSdkVersion in my manifest. I fixed this issue by changing <uses-permission> in my manifest to:

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

    (where the tools namespace is http://schemas.android.com/tools)

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

    For me the problem was that right after making the request, my main activity launched another activity. That superseded the dialog so it was never seen.

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

    The above information is good, but setting targetSdkVersion to 23 (or higher) is critical for Android to interpret the <uses-permission> tag in the manifest as "I will ask in code" instead of "I demand upon installation." Lots of sources will tell you that you need the <uses-permission> tag, but no one says why and if you don't have that value set, you're going to be as confused as I was for hours on end.

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

    I had this same issue.I updated to buildToolsVersion "23.0.3" It all of a sudden worked. Hope this helps anyone having this issue.

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

    I updated my target SDK version from 22 to 23 and it worked perfectly.

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