简体   繁体   中英

Locking android device from app

Please help me in how to lock the android device from an app.

DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

devicePolicyManager.lockNow();

Used above code but its not working.

Before Lock the screen you need to Enable Admin Permission.You can check whether device admin is active or not like

deviceManger.isAdminActive(compName);

if not then you have to enable it first, and then you can lock the device using

deviceManger.lockNow();  

For further information you can refer this:

Lock Screen programmatically

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM