3

I am working on an android app that should be used by students in some kind of practical test. 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.

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.

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!

Shira Elitzur
  • 433
  • 3
  • 9
  • To the user that downvoted my question, can you please explain your downvoting? I **did** search before posting and i believe that my question is clear. I will be happy to learn how to improve my question. – Shira Elitzur Apr 12 '17 at 05:57
  • This is a good question, and probably a very common one for anyone who ever attempts to use the task pinning API. Downvoters are on crack. – Kevin Krumwiede Jun 23 '17 at 21:02
  • https://issuetracker.google.com/issues/62957154 – Kevin Krumwiede Jun 23 '17 at 21:50

2 Answers2

0

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. You may refer to this too : How to be notified when screen pinning is turned off in Android 5.0 Lollipop?

Community
  • 1
  • 1
hadifikri
  • 434
  • 3
  • 10
  • I read the question in the link but it is not the same case and there was no good solution their without being device owner (which i can't). I tried to catch the onKeyDown or up of the two buttons that release the lock, but it didn't work. Without a better idea i think i will have to run some service that will check the lock status in a timer task or something. – Shira Elitzur Apr 23 '17 at 19:37
-1

https://developer.android.com/reference/android/app/ActivityManager.html#getLockTaskModeState()

Just use the function as stated in the link.

  • Thanks, but i'm looking for some event that occurs when the user lock/unlock if exist. Because if i want to have a log that will tell me when the student 'logged out' (unlocked...) i will have to check the state all the time if i will use that method – Shira Elitzur Apr 12 '17 at 04:48
  • 1
    @chen tian chuin Please do not post link-only answers. Links get broken - you should post the code or elaborate on you solution. – yakobom Apr 12 '17 at 05:02
  • @yakobom do you know if i have a way to handle the event of the unlocking? – Shira Elitzur Apr 12 '17 at 05:05
  • 1
    @Shira sorry, no. I was merely trying to keep fair answer quality as required here... – yakobom Apr 12 '17 at 05:27