小编fas*_*goc的帖子

Android shouldShowRequestPermissionRationale 有bug?

我认为有一个错误 shouldShowRequestPermissionRationale

代码是...

@Override
protected void onResume() {
    super.onResume();
    if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED &&
            ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {
        if(ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_COARSE_LOCATION) ||
                ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
            new AlertDialog.Builder(this)....show();
    } else {
        // do something...
}
Run Code Online (Sandbox Code Playgroud)

首先安装了应用程序,我们不允许该权限。所以当 onResume 被调用时,AlertDialog 应该出现。但是没有出现...

如果我们进入应用程序的设置,并允许权限。所以我们播放应用程序代码( // do something)。再次,我们进入应用程序的设置,拒绝权限。然后我们重新启动应用程序,就会出现 AlertDialog。

为什么应用程序会这样运行?

android android-permissions

4
推荐指数
1
解决办法
4926
查看次数

标签 统计

android ×1

android-permissions ×1