Locking an android phone (lock pattern or similar)

╄→尐↘猪︶ㄣ 提交于 2019-12-19 03:36:43

问题


Since LOCK_PATTERN_ENABLED was moved to Settings.Secure in Froyo my app can no longer lock the screen...

Does anyone know a workaround for this? Any way that my app can instantly lock the screen? No matter if its the autolock pattern or some kind of custom lock screen...


回答1:


This is a little cumbersome...

If you add a DeviceAdminReceiver to your app and the user enables it the security settings then you are allowd to call

DevicePolicyManager dpm = 
    (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
dpm.lockNow();

to lock the device immediately.

If you don't have a DeviceAdminReceiver in your app the call to .lock() will cause a SecurityException.



来源:https://stackoverflow.com/questions/2935006/locking-an-android-phone-lock-pattern-or-similar

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