简体   繁体   English

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

[英]how to run adb shell commands from android code?

I want to run these commands from java code: 我想从java代码运行这些命令:

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. 请帮我如何从Android代码运行。

You can use this method to run commands 您可以使用此方法运行命令

private void runShellCommand(String command) throws Exception {
    Process process = Runtime.getRuntime().exec(command);
    process.waitFor();
}

OK you will be needing Runtime class. 好的,你将需要Runtime类。 There is a good tutorial on executing shell commands here . 有上执行shell命令一个很好的教程在这里 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM