android M中权限更改的广播操作 [英] broadcast action on permission change in android M

查看:228
本文介绍了android M中权限更改的广播操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从设置"更改其许可权设置后,应用程序是否会广播或发出任何类型的警报?我有一种情况,当应用程序启动时,我们会开始某种日志记录,并且具有LOCATION GROUP权限.但是,当用户撤销此权限时,我们的应用程序将崩溃.用户取消日志时,找不到停止日志的任何方法.此日志记录来自3rd party库,因此我们也不能在两者之间放置任何检查权限检查.

does application gets any broadcast or any kind of alert when its permission setting is changed from Settings? I have got a scenario where we start some kind of logging when application starts and has got LOCATION GROUP permissions. But when user revokes this permission in between our application crashes. Not finding any way to stop the logging when user cancels it. This logging is from 3rd party library so we can not put any check permission check too in between.

推荐答案

从设置"更改其许可权设置后,应用程序是否会广播或发出任何类型的警报?

does application gets any broadcast or any kind of alert when its permission setting is changed from Settings?

没有记录.

如果用户撤销先前授予您的权限,则您的过程将终止.下次运行时,您将最终发现有关权限更改的信息,这是检查权限的一部分.

If the user revokes a permission that was previously granted to you, your process will be terminated. When you next run, you will wind up finding out about the permission change as part of checking for permissions.

如果用户授予先前被拒绝的权限,则您的过程不会终止.但是,再次致电checkSelfPermission()时,您会发现自己具有访问权限.

If the user grants a permission that was previously denied, your process is not terminated. However, once again, when you call checkSelfPermission(), you will find out that you have access.

这里的教训是:不要缓存权限查找结果.它们似乎是很便宜的电话,因此只需根据需要拨打checkSelfPermission().

The lesson here is: do not cache permission lookup results. They seem to be fairly cheap calls, so just call checkSelfPermission() as needed.

如果您的targetSdkVersion低于23,则checkSelfPermission()将无济于事,但您应该获取的是虚假数据,而不是SecurityException.对于位置修复,如果用户撤消了您的位置访问权限,则不应获得任何位置.

If your targetSdkVersion is below 23, checkSelfPermission() will not help, but you should be getting bogus data rather than a SecurityException. In the case of location fixes, you should not get any locations if the user has revoked your location access permissions.

但是当用户在两次应用崩溃之间撤消此权限时

But when user revokes this permission in between our application crashes

我还没有尝试过运行后台服务并且用户撤销许可的情况. 应该终止您的进程,因此当您下次服务运行时,您将了解有关权限更改的信息.如果您发现自己的进程不是 被终止,则可能表明Android中存在错误.

I have not tried a scenario where a background service is running and the user revokes a permission. It should be terminating your process, and so you would find out about the permission change when your service runs for the next time. If you are finding that your process is not being terminated, that may be a sign of a bug in Android.

这篇关于android M中权限更改的广播操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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