Android “onRequestPermissionsResult” not being called

左心房为你撑大大i 提交于 2019-12-02 02:23:11

MY_LOCATION_REQUEST_CODE should be a non-egative constant.

You should declare it as

private static final int MY_LOCATION_REQUEST_CODE = 1;

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)

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!