These document the use of lockNow()
from an app that's admin.
https://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#lockNow(int)
http://blogs.quovantis.com/android-device-administration-apis/
The basic process is:
create a DeviceAdminReceiver
register the receiver in the manifest, and give it the DEVICE_ADMIN_ENABLED
action
declare the security policies in an xml file
initialize a DevicePolicyManager
object in your onCreate()
method
call DevicePolicyManager.lockNow()
And that works beautifully. However, I'd like to be able to lock the screen without making my app an administrator perhaps by calling lockNow()
as an implicit intent. Is this possible?
Only a device admin with the right permissions can call that API.
Given that, either you must: