how to bring up lock screen in android?

你。 提交于 2019-12-02 11:06:23

问题


I want to bring up the lock screen of the device if a button is clicked. I searched a lot and know that could be done by DevicePolicyManager but don't know how to do that. I also found lots of examples but neither of them brought up the lock screen(with no error)(e.g. this or this) how to lock device using DevicePolicyManager?


回答1:


I also found lots of examples but neither of them brought up the lock screen(with no error)(e.g. this or this)

That second link should work. It looks similar to my LockMeNow sample app, which I know works, as I just demonstrated it in a training class two days ago.

You need to implement a DeviceAdminReceiver whose manifest entry contains a <meta-data> link to a policy document that says that you want the ability to <force-lock /> the device.

Then, the user needs to agree to this, by going into Settings > Security > Device Administrators and enable your app as a device administrator. There is code in both my sample and the one that you linked to that contains code that checks to see if the app is a device administrator, and if not leads the user into Settings to go enable it.

Once that is done, you can obtain a DevicePolicyManager and call lockNow().



来源:https://stackoverflow.com/questions/18546909/how-to-bring-up-lock-screen-in-android

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