简体   繁体   English

如何在Android 5.0 Lollipop中关闭屏幕固定时收到通知?

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

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. 我发现在Android 5.0中,当用户使用另一个应用程序打开屏幕固定时,将完全忽略startActivity(intent)调用。 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? 是否有任何类型的事件我可以注册以在屏幕固定关闭时收到通知,所以我可以重新尝试开始我的活动?

Here is method in ActivityManager class which tells status of current task if locked or not in case of screen pinning: 这是ActivityManager类中的方法,它告诉屏幕固定时是否锁定当前任务的状态:

!mActivityManager.isInLockTaskMode()

For more details check this link: http://developer.android.com/reference/android/app/ActivityManager.html#isInLockTaskMode%28%29 有关更多详细信息,请访问以下链接: http//developer.android.com/reference/android/app/ActivityManager.html#isInLockTaskMode%28%29

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 要了解如何将您的应用设为管理员应用:您可以在此处查看我以前的答案之一

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android Lollipop上关闭蓝牙时应用程序崩溃 - App Crash when Bluetooth is turned off on Android Lollipop 在Android中关闭屏幕时如何防止CPU“休眠”? - How to keep CPU from 'sleeping' when screen is turned off in Android? 屏幕打开/关闭时如何更新 Android 小部件? - How to update an Android widget when the screen is turned On/Off? 屏幕关闭时,Android加速度计无法正常工作 - Android accelerometer not working when screen is turned off Android-屏幕关闭或屏幕超时时终止应用 - Android - Kill an app when screen turned off or screen times out Android Lollipop-屏幕关闭时无法获取GPS位置 - Android Lollipop - GPS location not fetching when screen is off 屏幕关闭时,服务中的android加速计停止运行 - android accelerometer in service stops when screen is turned off 屏幕关闭时调用Android onStart()事件 - Android onStart() event is called when the screen is turned off 是否可以在 JavaScript 中检测到 Android 和 iOS 浏览器中的屏幕何时关闭 - Is it possible, in JavaScript, to detect when the screen is turned off in the Android & iOS browsers 屏幕关闭时,Android BroadcastReceiver不起作用 - Android BroadcastReceiver does'nt work when screen is turned off
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM