4

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.

Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27
ROR
  • 271
  • 3
  • 29
  • Shutdown is a root command.. therefor your app needs root permissions. So why not give it root permissions? – sridesmet Mar 31 '14 at 13:38
  • This topic will help you: http://stackoverflow.com/questions/16217294/how-to-grant-root-access-to-a-specific-application-from-source-code-instead-of-r – sridesmet Mar 31 '14 at 13:40
  • it doesn't help BTW Thanks pal – ROR Mar 31 '14 at 13:48

1 Answers1

2

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

Tapeshvar
  • 338
  • 1
  • 13
  • right so what should I do know which way is better ? and I don't wanna see this alert – ROR Mar 31 '14 at 13:54
  • but wait please I selected (Remember my choice) if I want do this task programmatically what should i do for this ? – ROR Mar 31 '14 at 14:03
  • 1
    That's not possible afaik :-) – sridesmet Mar 31 '14 at 14:05
  • Gudgip do know how to do (Remember my choice) programmatically – ROR Mar 31 '14 at 14:07
  • I don't think you can program the phone to remember that choice. It wouldn't be logic either, as it's a root privilege :-) But please tell me if you were capable of hiding it ;) – sridesmet Mar 31 '14 at 14:11
  • hhhhhhh Gudgip yeah you're right , that's my fault my question not clear I mean this : I don't wanna see this alert the image above , and I dont want create a program to make Remember that choice lol , I mean that choice – ROR Mar 31 '14 at 14:49