Question

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:

enter image description here

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

Was it helpful?

Solution

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:)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top