简体   繁体   中英

How to shut down Android phone, programmatically?

How to make shut down in Android programmatically, I searched for the question and I found many answer the strongest answer said your phone must be ROOT, now my phone is root and my code working fine but when I execute this code below I get an alert like this image below.

Code:

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

My result:

在此输入图像描述

Now how to eliminate this alert I want to shut down directly when I press my shut down program button, without getting this alert.

Even if your phone is rooted, when apps that require root are accessing these system areas it will prompt for permission from the user atleast once(1st time of using the app). Either you can allow each time which will allow root permissions for your app for specified time limit(usually 15 mins) or you can select the "Remember my choice" and allow permanent access to your app this way. In case you allowed once with the "Remember my choice" then you will have to manually change this permission from your super user app.

NOTE: Once if your device is rooted, you will get an app named "SuperSU" or "Superuser" in your device which will display all the apps that requires ROOT permission and the default access level of these apps.

Hope this helps:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM