我想从Java代码中运行这些命令:
adb shell settings put secure location_providers_allowed gps, wifi,network
a broadcast -a android.location.GPS_ENABLED_CHANGE --ez enabled true
请帮我学习如何从Android代码中运行。我想从Java代码中运行这些命令:
adb shell settings put secure location_providers_allowed gps, wifi,network
a broadcast -a android.location.GPS_ENABLED_CHANGE --ez enabled true
请帮我学习如何从Android代码中运行。private void runShellCommand(String command) throws Exception {
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
}
好的,您将需要使用Runtime
类。执行shell命令的教程可以在这里找到。如果需要快速回答,请尝试以下方法:
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);