問題描述
Android 6.0 中的權限更改回調 (Permission changed callback in Android 6.0)
我想知道當用戶在 Android 6.0 上更改應用設置中的權限時,是否有某種方法可以收到通知。我一直在尋找這個答案,但沒有運氣。你知道廣播接收器和一些特定的意圖是否可行?或者也許有一些技巧可以實現這一點?
參考解法
方法 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).
(by Aleksander Mielczarek、Tal Kanel、Thomas Wanschik)