棉花糖应用程序权限吊销通知? [英] Marshmallow app permission revoke notification?

查看:102
本文介绍了棉花糖应用程序权限吊销通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android 6.0(棉花糖)中,即使从应用程序内部授予权限,用户也可以撤消特定的应用程序权限.我知道我可以使用ContextCompat.checkSelfPermission()检查权限.但是,当用户撤销我的应用程序权限之一时,是否有一种方法可以通知我的应用程序,而无需使用ContextCompat.checkSelfPermission()进行重复检查?也许是广播/意图或类似的东西?

In Android 6.0 (Marshmallow), users can revoke specific app permissions, even after granting it from inside the app. I know I can check permissions with ContextCompat.checkSelfPermission(). But Is there a way for my app to get notified when the user revokes one of my app's permissions, without repeated checking with ContextCompat.checkSelfPermission()? Maybe a broadcast/intent or something similar?

在此先感谢您的帮助.

推荐答案

如果您的应用需要危险的权限,则每次执行需要该权限的操作时,都必须检查您是否具有该权限.用户始终可以自由地撤消该权限,因此即使该应用程序昨天使用了权限,也不能认为它今天仍然具有该权限.

If your app needs a dangerous permission, you must check whether you have that permission every time you perform an operation that requires that permission. The user is always free to revoke the permission, so even if the app used a permission yesterday, it can't assume it still has that permission today.

要检查您是否具有权限,请调用ContextCompat.checkSelfPermission()方法.例如,以下代码片段显示了如何检查活动是否有权写入日历:

To check if you have a permission, call the ContextCompat.checkSelfPermission() method. For example, this snippet shows how to check if the activity has permission to write to the calendar:

// Assume thisActivity is the current activity
int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
        Manifest.permission.WRITE_CALENDAR);

如果应用具有许可,则该方法返回PackageManager.PERMISSION_GRANTED,应用可以继续进行操作.如果该应用没有该权限,则该方法返回PERMISSION_DENIED,并且该应用必须明确向用户询问权限.

If the app has the permission, the method returns PackageManager.PERMISSION_GRANTED, and the app can proceed with the operation. If the app does not have the permission, the method returns PERMISSION_DENIED, and the app has to explicitly ask the user for permission.

这篇关于棉花糖应用程序权限吊销通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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