Shut down your Android phone programatically

Asked 2 years ago, Updated 2 years ago, 32 views

Can I shut down my Android phone on the program?

Second question: How do we programatically lock and unlock Android screens?

I tried the following code, but it didn't work.

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

lock.disableKeyguard(); // disable code

lock.greenableKeygard();// enable code

And I also wrote a permission.

android

2022-09-22 21:31

1 Answers

If you need a reboot, you can use PowerManager (the reboot is not guaranteed because the OS may reject it)

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

REBOOT permission is required.

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

And check the logcat that occurs when you try enable/disable keyguard. Could you put it up here, if possible?


2022-09-22 21:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.