如何从Android代码中运行adb shell命令?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (1698)

我想从java代码中运行这些命令:

adb shell settings put secure location_providers_allowed gps, wifi,network 

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

如何运行Android代码?

提问于
用户回答回答于
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);
用户回答回答于
private void runShellCommand(String command) throws Exception {
    Process process = Runtime.getRuntime().exec(command);
    process.waitFor();
}

扫码关注云+社区

领取腾讯云代金券