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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…