9

I want to run these commands from java code:

adb shell settings put secure location_providers_allowed gps, wifi,network 

a broadcast -a android.location.GPS_ENABLED_CHANGE --ez enabled true

Please help me how to run from Android code.

Behnam
  • 6,224
  • 6
  • 33
  • 65
Getaw Dejen
  • 181
  • 1
  • 3
  • 12

2 Answers2

8

You can use this method to run commands

private void runShellCommand(String command) throws Exception {
    Process process = Runtime.getRuntime().exec(command);
    process.waitFor();
}
Rami Jarrar
  • 4,387
  • 6
  • 33
  • 50
3

OK you will be needing Runtime class. There is a good tutorial on executing shell commands here. For a quick answer, try this:

String commandToRun = "adb shell settings put secure location_providers_allowed gps, wifi,network a broadcast -a android.location.GPS_ENABLED_CHANGE --ez enabled true";
Runtime.getRuntime().exec(commandToRun);
Sandro Machado
  • 9,263
  • 4
  • 33
  • 57
Behnam
  • 6,224
  • 6
  • 33
  • 65