tags:

views:

108

answers:

2

HI all, Can we switch of the phone programmatically..?Please let me know how to do this..?

An my second question is..

how to lock and unlock the screen in android?

i am using following snippet but it didnt worked for me..

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE); 
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); 

lock.disableKeyguard(); // to disable

lock.reenableKeygaurd();// to enable

and i used the permission also.. Help me to do this in correct way..thanks in advance

+2  A: 

You cannot do this from an ordinary SDK application. Only applications signed with the system firmware signing key can do this.

CommonsWare
And with good reason!
Delan Azabani
+1  A: 

You could possibly use the PowerManager to make it reboot (this does not guarantee that it'll reboot - OS may cancel it):

http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String)

It requires the REBOOT permission:

http://developer.android.com/reference/android/Manifest.permission.html#REBOOT

Can you also check your logcat when trying to enable/disable keyguard, and post what's there?

xil3
@xil3: You cannot do a reboot from an ordinary SDK application. Only applications signed with the system firmware signing key can do this.
CommonsWare
Ah ok, fair enough - well I'll leave this up anyways so that he can read up about the PowerManager...
xil3