Android的米 - 检查运行许可 - 如何确定用户选中"永远不要再问"? [英] Android M - check runtime permission - how to determine if the user checked "Never ask again"?

查看:429
本文介绍了Android的米 - 检查运行许可 - 如何确定用户选中"永远不要再问"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据该:<一href="http://developer.android.com/$p$pview/features/runtime-permissions.html#coding">http://developer.android.com/$p$pview/features/runtime-permissions.html#coding一个应用程序可以检查运行权限和要求的权限,如果它没有被授予了。将显示下面的对话框然后:

According to this: http://developer.android.com/preview/features/runtime-permissions.html#coding an app can check for runtime permissions and request permissions if it hasn't been granted already. The following dialog will be displayed then:

如果用户拒绝的重要权限,海事组织为什么许可是必要的,什么样的影响下降,有一个应用程序应该显示的解释。该对话框中有两个选项:1)重试一次(权限再次请求),2)拒绝(应用程序将工作没有这个权限)

In case the user declines an important permission, imo an app should display an explanation why the permission is needed and what impact declining has. That dialog has two options: 1) re-try again (permission is requested again), 2) deny (app will work without that permission).

如果用户检查不再询问,然而,不应该显示与解释的第二个对话框,特别是如果用户已经拒绝过一次。 现在的问题是:如何我的应用程序知道用户是否选中了不再询问?国际海事组织的onRequestPermissionsResult(INT申请code,的String []的权限,INT [] grantResults)并没有给我的信息。

If the user checks "Never ask again" however, the second dialog with the explanation shouldn't be shown, especially if the user already declined once before. Now the question is: how does my app know whether the user has checked the "Never ask again"? IMO the onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) doesn't give me that information.

这是第二个问题是:谷歌是否有计划将在权限对话框,可以解释为什么该应用程序所需要的权限的自定义消息?这样,永远不会有第二个对话框,肯定会做出一个更好的UX。

A second question would be: does Google have plans to incorporate a custom message in the permission dialog that would explain why the app needs the permission? That way there would never be a second dialog which would certainly make for a better ux.

推荐答案

开发preVIEW 2带来了一些改变,如何权限的应用程序请求(参见<一href="http://developer.android.com/$p$pview/support.html#$p$pview2-notes">http://developer.android.com/$p$pview/support.html#$p$pview2-notes).

Developer Preview 2 brings some changes to how permissions are requested by the app (see also http://developer.android.com/preview/support.html#preview2-notes).

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

The first dialog now looks like this:

有没有不要再次显示复选框(不像开发商preVIEW 1)。如果用户拒绝的权限,如果权限的应用程序至关重要它可能present另一个对话框来解释应用程序要求的权限,例如原因像这样的:

There's no "Never show again" check-box (unlike developer preview 1). If the user denies the permission and if the permission is essential for the app it could present another dialog to explain the reason the app asks for that permission, e.g. like this:

如果用户再次拒绝该应用程序要么关闭,如果这是绝对需要该权限或保留有限的功能运行。如果用户重新考虑(和选择重试),允许再次请求。这一次,提示是这样的:

If the user declines again the app should either shut down if it absolutely needs that permission or keep running with limited functionality. If the user reconsiders (and selects re-try), the permission is requested again. This time the prompt looks like this:

在不再询问复选框显示的第二次。如果用户再次否认与复选框被选中罢了应该发生。 该复选框被选中可以使用Activity.shouldShowRequestPermissionRationale(字符串)来确定是否,例如:像这样的:

The second time the "Never ask again" check-box is shown. If the user denies again and the check-box is ticked nothing more should happen. Whether or not the check-box is ticked can be determined by using Activity.shouldShowRequestPermissionRationale(String), e.g. like this:

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

这就是Android的文件说(<一href="https://developer.android.com/$p$pview/features/runtime-permissions.html#explain-need">https://developer.android.com/$p$pview/features/runtime-permissions.html#explain-need):

要帮助找到你需要提供额外的情况下,   说明中,系统提供了   Activity.shouldShowRequestPermissionRationale(String)方法。本   如果应用程序已请求此权限的方法返回true   previously,用户拒绝了这一要求。这表示您   或许应该向用户说明为什么你需要的权限。

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.

如果用户拒绝了在过去的许可请求和选择   在不要在许可请求的系统对话框再问选项,   此方法返回false。该方法还返回false如果该设备   政策从具有许可禁止应用程序。

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.

要知道,如果用户拒绝与永远不再问你能再次检查的 shouldShowRequestPermissionRationale 的方法,在你的onRequestPermissionsResult当用户未授予权限。

To know if the user denied with "never ask again" you can check again the shouldShowRequestPermissionRationale method in your onRequestPermissionsResult when the user did not grant the permission.

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == REQUEST_PERMISSION) {
        // for each permission check if the user grantet/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) {
                boolean showRationale = shouldShowRequestPermissionRationale( permission );
                if (! showRationale) {
                    // user denied flagging 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 denied WITHOUT never ask again
                    // this is a good place to explain the user
                    // why you need the permission and ask if he want
                    // to accept it (the rationale)
                } else if ( // possibly check more permissions... ) {}
            }
        }
    }
}

您可以打开你的应用程序与此code设置:

You can open your app setting with this code:

Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivityForResult(intent, REQUEST_PERMISSION_SETTING);

没有方法直接发送用户到授权页面的

There is no way of sending the user directly to the Authorization page.

这篇关于Android的米 - 检查运行许可 - 如何确定用户选中&QUOT;永远不要再问&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆