I'm using device-admin policy to lock(lockNow),but how can I lock repeatedly for specific amount of time.In the mentioned time interval the user should not be able to unlock the phone!
Asked
Active
Viewed 102 times
3
-
Check this out how to lock https://stackoverflow.com/a/19782558/2462531 Use Alarm manager to do it repeatedly. – Shailendra Madda Apr 17 '18 at 03:01
1 Answers
2
There is no official API available to achieve your intended behavior. I would strongly recommend to not obstruct the user's actions. But if you want to proceed, you can try following workaround:
- When
lockNow
is triggered, the screen is turned OFF. You can register forSCREEN_ON
BroadcastReceiver in a foreground service and then whenever your screen is turned on you can calllockNow
. Stop the service and release the broadcast receiver once your timeout has been achieved. The drawback is bad user experience. - You can create a Overlay layout which with Black background and cover user's screen. You can also present some timer to indicate remaining time. Once timeout is achieved, remove the overlay. This will provide better user experience. You might need to take care of overlay permission in this case.

Sagar
- 23,903
- 4
- 62
- 62
-
I have used a while loop that will run till the specified time and it will be locking the screen continuously.Will that be ok ? – Abdul Khader Apr 17 '18 at 10:27
-
1It would be battery consuming. And the user experience wont be great. User could easily think that your app is causing some issue and would try to uninstall it. I would recommend the overlay approach which will block the UI and you can display meaningful text/graphics to user. This will make your app look more responsive. – Sagar Apr 17 '18 at 10:35