How to be notified when screen pinning is turned off in Android 5.0 Lollipop?

孤街醉人 提交于 2019-12-05 05:52:26

问题


I have an app that runs in the background and starts an activity when a certain event occurs on the phone. I'm finding with Android 5.0 that when the user has screen pinning turned on with another app, the startActivity(intent) call is ignored completely. My app doesn't know that the activity didn't start, so the user then won't have another chance to see the activity until they manually reopen my app.

Is there any sort of event I can register for to be notified when screen pinning is turned off, so I can reattempt to start my activity?


回答1:


Here is method in ActivityManager class which tells status of current task if locked or not in case of screen pinning:

!mActivityManager.isInLockTaskMode()

For more details check this link: http://developer.android.com/reference/android/app/ActivityManager.html#isInLockTaskMode%28%29




回答2:


Your app must be a device administrator (with administration rights granted by user). Once you have done that, you can implement this callback:

AdminReceiver.onLockTaskModeExiting(Context context, Intent intent)

to do something when pinning mode is stopped.

To see how to make your app an Administrator app : you can check one of my previous answer here



来源:https://stackoverflow.com/questions/26855524/how-to-be-notified-when-screen-pinning-is-turned-off-in-android-5-0-lollipop

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