android用户确认权限,Android M – 检查运行时权限 – 如何确定用户是否选中“不再询问”?...

开发者预览2对应用程序请求权限的方式带来了一些变化(参见

http://developer.android.com/preview/support.html#preview2-notes)。

第一个对话框现在看起来像这样:

00cc474ed6dacc7d7d8e3e0297d55052.png

没有“不再显示”复选框(与开发者预览1不同)。如果用户拒绝了权限,并且如果权限对于应用程序是必要的,则它可以呈现另一个对话框来解释应用程序请求该权限的原因。喜欢这个:

526ab579c3ea8517fe5325d6ed45ed25.png

如果用户再次拒绝应用程序应该关闭,如果它绝对需要该权限或继续运行有限的功能。如果用户重新考虑(并选择重试),则再次请求许可。这一次的提示如下:

638fd07201be4be4f718e3469c400d88.png

第二次显示“不再询问”复选框。如果用户再次拒绝并且复选框被勾选,则不应再发生。

可以通过使用Activity.shouldShowRequestPermissionRationale(String)来确定是否勾选复选框。喜欢这个:

if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_CONTACTS)) {...

To help find the situations where you need to provide extra

explanation, the system provides the

Activity.shouldShowRequestPermissionRationale(String) method. This

method returns true if the app has requested this permission

previously and the user denied the request. That indicates that you

should probably explain to the user why you need the permission.

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. The method also returns false if the device

policy prohibits the app from having that permission.

要知道用户是否拒绝“不再询问”,可以在用户未授予权限时再次检查onRequestPermissionsResult中的shouldShowRequestPermissionRationale方法。

@Override

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

if (requestCode == REQUEST_PERMISSION) {

// for each permission check if the user granted/denied them

// you may want to group the rationale in a single dialog,

// this is just an example

for (int i = 0, len = permissions.length; i < len; i++) {

String permission = permissions[i];

if (grantResults[i] == PackageManager.PERMISSION_DENIED) {

// user rejected the permission

boolean showRationale = shouldShowRequestPermissionRationale( permission );

if (! showRationale) {

// user also CHECKED "never ask again"

// you can either enable some fall back,

// disable features of your app

// or open another dialog explaining

// again the permission and directing to

// the app setting

} else if (Manifest.permission.WRITE_CONTACTS.equals(permission)) {

showRationale(permission, R.string.permission_denied_contacts);

// user did NOT check "never ask again"

// this is a good place to explain the user

// why you need the permission and ask if he wants

// to accept it (the rationale)

} else if ( /* possibly check more permissions...*/ ) {

}

}

}

}

}

您可以使用此代码打开应用设置:

Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);

Uri uri = Uri.fromParts("package", getPackageName(), null);

intent.setData(uri);

startActivityForResult(intent, REQUEST_PERMISSION_SETTING);

没有办法将用户直接发送到授权页面。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值