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

查看:38
本文介绍了为 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:

请求权限

如果您的应用需要应用中列出的危险权限manifest,它必须要求用户授予权限.安卓提供了几种可用于请求权限的方法.打电话这些方法会弹出一个标准的 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().这个方法返回真如果该应用之前已请求此权限,但用户拒绝了请求.

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天全站免登陆