- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我认为有一个错误 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...
}
首先安装了应用程序,我们不允许该权限。所以当 onResume 被调用时,AlertDialog 应该出现。但它没有出现...
如果我们进入应用程序的设置,并允许权限。所以我们播放应用程序代码(//做某事
)。再次,我们进入应用程序的设置,拒绝权限。然后我们重新启动应用程序,出现 AlertDialog。
为什么应用会这样运行?
最佳答案
来自开发者文档:
shouldShowRequestPermissionRationale()
This method returns true if the app has requested this permission previously and the user denied the request.
Note: If the user turned down the permission request in the past and chose the Don't ask again option in the permission request system dialog, this method returns false.
问题是您在使用前没有请求权限
ActivityCompat.requestPermissions();
因此它不显示对话框。
当您从“设置”手动授予权限或拒绝权限时,它假定您拒绝了该权限,这就是它显示警告对话框的原因。
关于Android shouldShowRequestPermissionRationale 有错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39738711/
我想在运行时请求权限。我查看了官方的 android 开发者网站,它说如果权限先前被拒绝,shouldShowRequestPermissionRationale 返回 true,如果权限被拒绝,则返
我认为有一个错误 shouldShowRequestPermissionRationale 代码是... @Override protected void onResume() { super
我正在检查并获得 API 级别 23 及更高级别用户的许可。所以这对我来说是一件令人困惑的事情,android.com 说: shouldShowRequestPermissionRationale(
我向我的应用添加了位置权限。现在安装应用程序时,它会请求用户许可。这是我的代码: if (fragment.shouldShowRequestPermissionRationale(Manifest.
shouldShowRequestPermissionRationale方法返回 false第一次。 我在 fragment 中有以下代码: if (shouldShowRequestPermissi
如何在调用权限之前使用shouldShowRequestPermissionRationale并在Activity中使用。 因为在 ActivityCompat.requestPermissions
目前我正在编写一个读取用户电话号码的安卓应用程序。因为该应用程序是为 SDK 23+(目标 sdk 27)开发的,所以我必须请求读取短信权限。如果用户第一次拒绝该权限,则应出现一个对话框,解释电话
我正在构建一个需要用户位置的应用程序。我正在关注来自 here 的 Android 培训文档其中说: shouldShowRequestPermissionRationale return the b
下面是我的代码,我调用此代码以获得运行时权限。在这种情况下,“shouldshowrequestpermissionrationale 总是返回 false”。我找不到解决方案为什么会这样。因此,未显
我正在阅读有关 Android M 中新权限模型的官方文档。它讨论了 shouldShowRequestPermissionRationale() 函数,如果应用程序请求此函数,该函数将返回 true
我是一名优秀的程序员,十分优秀!