Permission changed callback in Android 6.0

隐身守侯 提交于 2019-12-06 03:17:43

问题


I wonder if there is some way to being notified when user changes permission in app settings on Android 6.0. I was looking for this answer with no luck. Do you know if it is possible with broadcast receiver and some specific Intent? Or maybe there is some hack to achieve this?


回答1:


according to this answer, there is no any broadcast/event that you can intercept when permission revoked from the settings screen by the user.

but the "good" news, in assumption that it's your concern - your process will be terminated automatically by the system if there will be any changes to the permission status while your app process was alive




回答2:


You can keep track of this by using the AlarmManager to periodically check for the permissions your're interested in (for example every 30 seconds) and compare it to the value you saw the last time (saved in SharedPreferences for example). In the worst case you won't get updates within the timer interval, however it should be very unlikely that the user changes a permission multiple times within a short time interval.

Keep in mind that you have to start the periodical checks when the device boots up (android.intent.action.BOOT_COMPLETED).



来源:https://stackoverflow.com/questions/34198991/permission-changed-callback-in-android-6-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!