Android “onRequestPermissionsResult” not being called

前端 未结 3 673
旧巷少年郎
旧巷少年郎 2021-01-21 16:42

I\'m trying to implement Marshmallow\'s permission support, but my code inside \"onRequestPermissionsResult\" is never called. The \"onCreate\" and \"onMapReady\" parts of the c

相关标签:
3条回答
  • 2021-01-21 17:19

    This line will never evaluate to true:

    permissions[0] == android.Manifest.permission.ACCESS_FINE_LOCATION
    

    Because you are comparing these two strings by reference.

    You should use TextUtils.equals()

    TextUtils.equals(permissions[0], android.Manifest.permission.ACCESS_FINE_LOCATION)
    
    0 讨论(0)
  • 2021-01-21 17:27

    MY_LOCATION_REQUEST_CODE should be a non-egative constant.

    You should declare it as

    private static final int MY_LOCATION_REQUEST_CODE = 1;
    
    0 讨论(0)
  • 2021-01-21 17:34

    I have the same issue, the issue was only on API 23 (Android M). And that because I was using the flag android:noHistory="true" in the manifest when declaring the activity:

    <activity   android:name=".view.activity.SplashScreenActivity"
                android:noHistory="true">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
    </activity>
    

    That because when showing the permission dialog the activity will be finished by the system because of that flag.

    Removing it, or setting it to false fixes my issue.

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