为Android M权限对话框提供自定义文本 [英] Provide custom text for Android M permission dialog

查看:782
本文介绍了为Android M权限对话框提供自定义文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为系统对话框提供自定义文本,当用户被要求授予权限时显示该文本?

Is it possible to provide a custom text for the system dialog which is displayed when the user is asked to grant permission?

推荐答案

否,您无法自定义对话框的文本,但是可以在请求权限之前提供说明.引用自 developer.android.com :

No, you can't customize the text of the dialog, but you can provide an explanation before request the permission. Quoting from developer.android.com:

请求权限

如果您的应用需要该应用中列出的危险许可 清单中,它必须要求用户授予许可.安卓 提供了几种可用于请求权限的方法.呼唤 这些方法会打开一个标准的Android对话框,您无法 自定义.

If your app needs a dangerous permission that was listed in the app manifest, it must ask the user to grant the permission. Android provides several methods you can use to request a permission. Calling these methods brings up a standard Android dialog, which you cannot customize.

说明应用为何需要权限

在某些情况下,您可能想帮助用户理解为什么 您的应用需要权限.例如,如果用户启动 摄影应用程序,用户可能不会对此应用程序感到惊讶 要求使用相机的许可,但用户可能不会 了解应用程序为何要访问用户的位置,或者 联系人.在申请许可之前,您应该考虑 向用户提供说明.请记住,您不想要 用说明让用户不知所措;如果您提供太多 解释,用户可能会发现该应用令人沮丧,并将其删除.

In some circumstances, you might want to help the user understand why your app needs a permission. For example, if a user launches a photography app, the user probably won't be surprised that the app asks for permission to use the camera, but the user might not understand why the app wants access to the user's location or contacts. Before you request a permission, you should consider providing an explanation to the user. Keep in mind that you don't want to overwhelm the user with explanations; if you provide too many explanations, the user might find the app frustrating and remove it.

您可能会使用的一种方法是仅在以下情况下提供解释: 用户已经拒绝了该权限请求.如果用户继续 尝试使用需要许可但仍保留的功能 拒绝许可请求,这可能表明该用户 不明白为什么该应用需要获得许可才能提供 功能.在这种情况下, 显示一个解释.

One approach you might use is to provide an explanation only if the user has already turned down that permission request. If a user keeps trying to use functionality that requires a permission, but keeps turning down the permission request, that probably shows that the user doesn't understand why the app needs the permission to provide that functionality. In a situation like that, it's probably a good idea to show an explanation.

为帮助查找用户可能需要解释的情况, Android提供了一种实用程序方法, shouldShowRequestPermissionRationale().如果此方法返回true 该应用先前已请求此权限,并且用户被拒绝 请求.

To help find situations where the user might need an explanation, Android provides a utiltity method, shouldShowRequestPermissionRationale(). This method returns true if the app has requested this permission previously and the user denied the request.

这篇关于为Android M权限对话框提供自定义文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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