How to shutdown an Android mobile programmatically?

android turn off screen programmatically
code to shutdown android phone
how to reboot android device programmatically
how to turn off backlight android programmatically
app to restart android phone
android shutdown command
android sleep programmatically
android code to switch off phone

Is it possible to shutdown the mobile programmatically. that is with out using su commands..


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?

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

How to shut down the device programmatically?, The hardware shutdown button of the device launches a dialog with shutdown options defined in 'Start' > 'Settings' > 'System' > 'Intermec Settings' > 'Device Settings' > 'Power Management' > 'Power Button' > 'Power Button Screen'. /** * Low-level function turn the device off immediately, without trying * to be clean. Most people should use * {@link android.internal.app.ShutdownThread} for a clean shutdown. * * @deprecated * @hide */ @Deprecated public static native void shutdown(); try using: su reboot -p. This works on some devices however it does not shutdown cleanly.


It is possible, but you need a Rooted Android device with Superuser access. You can't do it without Root unless your app is signed with the System Firmware Key. Try using the following code:

Shutdown:

try {
    Process proc = Runtime.getRuntime()
                    .exec(new String[]{ "su", "-c", "reboot -p" });
    proc.waitFor();
} catch (Exception ex) {
    ex.printStackTrace();
}

Reboot:

Same code, just use "reboot" instead of "reboot -p".

[On an other note: I read somewhere that these commands do not work on Stock HTC ROMs, but haven't confirmed myself]

How to shutdown the android device programmatically?, Android. A few customer launcher apps provide a way to shutdown / restart the I meant consumer devices such as android phone or tablet 0. If you have the sigOrSystem permission android.permission.SHUTDOWN you can raise the protected ACTION_REQUEST_SHUTDOWN Intent like this: Intent intent = new Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN"); intent.putExtra("android.intent.extra.KEY_CONFIRM", false); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);


This is the code i use to perform any system command.

void shutdown_sys()
{
    Process chperm;
    try {
        chperm=Runtime.getRuntime().exec("su");
          DataOutputStream os = 
              new DataOutputStream(chperm.getOutputStream());

              os.writeBytes("shutdown\n");
              os.flush();

              chperm.waitFor();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Call this function from your android App. It will work if su is functional in your system. Let me know in case it does not work. I dont have an Android base ready to test. But the same works for reboot. So shutdown is also a linux shell command which ithink will be there in Android as well.. All the best

Shut down Android device programmatically, Is there any way to programmatically shut down an Android device? I But there are some anti theft app which can shut down phone upon  The hardware shutdown button of the device launches a dialog with shutdown options defined in 'Start' > 'Settings' > 'System' > 'Intermec Settings' > 'Device Settings' > 'Power Management' > 'Power Button' > 'Power Button Screen'. Looking at the available options at 'Screen Options Displayed', there are different 'shutdown' options: Screen off.


With rooted shell command type in, svc power shutdown works for me in android 7.1

Shutdown android phone programmatically, The permissions can't be set programmatically. Android Phone Turning Off Automatically. How To Set Auto Shutdown In Android Nougat Phones? Android  I know this question has been asked in the forum before, but I found no useable answer: Is there any way to programmatically shut down an Android device? I mean instant shut down without the need to use the default Android touch screen menu to switch off the device?


I don't see any resemblance with your title and the code snippet in the body. The snippet is related with KeyGuardManager which is used for lock and unlock the key pad.

In order to shutdown your phone you will need to use PowerManager or SU commands. (On rooted devices.)

[APP][REQUEST][CODE] Android PowerManager, Can anyone explain how to shut down android phone using PowerManager? PowerManager pm = (PowerManager)  On most Android devices (phones and tablets), you can force restart your device by holding the Power button while holding the Volume Down button at the same time. Hold them down until the phone goes ‘blank’ (finally powers off) and then boots up (starts) again. On a few Android phones, you have to hold down the Power button and both Volume buttons.


How do I programmatically “restart” an Android app?, How do I programmatically “restart” an Android app? AndroidMobile DevelopmentApps/Applications. There are some situations, we need to  It's not possible to root my android 5 phone, there is no custom firmware, and no current one-click-root bugs. I would like to reboot my mobile every night while charging (wireless charger), but I have not found a way to do that. I could even write an app for that if it's somehow possible. Is there any "legal" way to reboot phone programmatically?


android.os.PowerManager.reboot java code examples, Language to have android phone reboot when there is a certain amount of failed password attempts Android - How to restart system_process programmatically? How can i turn off the android emulator by using code in eclipse? This example demonstrates how do I programmatically “restart” an Android app. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken a text view.


Any way to reboot device programmatically without root?, After several weeks of uptime my mobile phone becomes slow. When I reboot it everything is smooth again. It's not possible to root my android 5 phone, there is  A few customer launcher apps provide a way to shutdown / restart the android device with some custom button in their UI. I am working on a experimental launcher app, and would like to have a way to shutdown / restart the device, but the documentation out there says that it is not possible with the newer android api's.