开发者

Device Locking in Android

开发者 https://www.devze.com 2023-04-03 18:41 出处:网络
I need to lock my phone without using the device physical button.I created an Activity that contains a Button. Clicking the Button should lock the phone (i.e it should be like this http://www.freeimag

I need to lock my phone without using the device physical button. I created an Activity that contains a Button. Clicking the Button should lock the phone (i.e it should be like this http://www.freeimagehosting.net/2dca开发者_JAVA技巧f)

Can any one help me whit this? And the thing is it is not possible using keyguard manager or power manager because it is disabling and enabling the locking system.

Currently the code is done but some bugs are occuring... Here is my code

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


From 2.2 (I think) you can use DevicePolicyManager:

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

and then:

devicePolicyManager.lockNow();

Edit:

For this solution you have to add a device admin e.g.:

Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);  
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, securemeAdmin);


You should use PowerManager api. Refer here. Call goToSleep method.

0

精彩评论

暂无评论...
验证码 换一张
取 消