我想从java代码中运行这些命令:
adb shell settings put secure location_providers_allowed gps, wifi,network
a broadcast -a android.location.GPS_ENABLED_CHANGE --ez enabled true
请帮助我如何从Android代码运行。
发布于 2015-07-31 03:00:24
可以使用此方法运行命令
private void runShellCommand(String command) throws Exception {
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
}
发布于 2015-07-31 03:21:09
好的,您将需要Runtime
类。有一个关于执行外壳命令here的很好的教程。要获得快速答案,请尝试以下命令:
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);
https://stackoverflow.com/questions/31731728
复制相似问题