[英]How to detect lock and unlock of screen pinning on android
I am working on an android app that should be used by students in some kind of practical test. 我正在开发一个Android应用程序,学生应该在某种实践测试中使用它。 I am using the screen pinning that was introduced in Lollipop ( startLockTask() ), so when my app is launched the user needs to allow the locking. 我使用的是Lollipop( startLockTask() )中引入的屏幕固定,因此启动我的应用程序时,用户需要允许锁定。
I couldn't find a way to know when the user click ok for the locking and when he unlock the pinning? 我无法找到一种方法来知道用户何时单击“确定”进行锁定以及何时解除锁定? (The user can cancel the lock by holding both the Back and Recent buttons). (用户可以通过同时按住“后退”和“最近”按钮来取消锁定)。 I am not looking for a way to know if the user currently in lock screen (getLockTaskModeState ()), i want to know if i have a way to handle the events of locking or unlocking. 我不是在寻找一种方法来了解用户当前是否处于锁定屏幕 (getLockTaskModeState()),我想知道是否有一种方法来处理锁定或解锁事件 。
I want that in the begining of the test i will be able to send information to my server if the users 'logged in' properly (by allowing the lock), and as well if the user unlock the device before the end of the test. 我希望在测试开始时,如果用户正确地“登录”(通过允许锁定),并且用户在测试结束之前解锁了设备,我将能够向服务器发送信息。
EDIT 编辑
Hey, people! 嘿,人! Please explain yourselves after downvoting! 投票后请自行解释! If I wasn't exaplaining myself - i will try again if you will let me know. 如果我不自责-如果您让我知道,我会再试一次。 I read a lot of questions and answers about general lock screen, but not the one of app pinning, I also read about check the status of the current task- if it is locked or not, but i didn't find answer to what i am asking - is there a way to handle the event of unlocking the 'screen pinning' of a specific app. 我读了很多有关常规锁定屏幕的问题和答案,但不是应用程序固定的问题和答案,我还阅读了有关检查当前任务状态的信息-是否已锁定,但我没有找到答案询问-是否有办法处理解锁特定应用程序的“屏幕固定”事件。 So please, explain your downvotes! 因此,请解释一下你的反对意见!
Device Admin Recevier class give you the event of pinning and unpinning... However the example use the class when the installed app is provisioned for device owner.. Not sure if you could use it. Device Admin Recevier类为您提供了固定和取消固定的事件...但是,当为设备所有者预配已安装的应用程序时,该示例将使用该类。不确定是否可以使用它。 You may refer to this too : How to be notified when screen pinning is turned off in Android 5.0 Lollipop? 您也可以参考此内容: 在Android 5.0 Lollipop中关闭屏幕固定时如何通知?
https://developer.android.com/reference/android/app/ActivityManager.html#getLockTaskModeState() https://developer.android.com/reference/android/app/ActivityManager.html#getLockTaskModeState()
Just use the function as stated in the link. 只需使用链接中所述的功能即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.