Programmatically switching off Android phone

后端 未结 6 1606
清歌不尽
清歌不尽 2020-11-22 13:02

Can we switch off an Android phone programmatically?

I am using following snippet but it didn\'t work for me.

KeyguardManager keyguardManager = (Keyg         


        
6条回答
  •  长情又很酷
    2020-11-22 13:41

    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?

提交回复
热议问题