开发者

Device Locking in Android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜