Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

broadcast action on permission change in android M

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Not that is documented.

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.

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.

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...