public static int execCommand(String command) throws IOException {
return execCommand(new String[] { "sh","-c", command });
}
/**
* Execute shell command
* @param command Shell command array
* @return Result
* @throws IOException Throws when occurs #IOException
*/
public static int execCommand(String[] command) throws IOException {
Log.d("Darrick", "command = "+command);
int result = RESULT_FAIL;
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec(command);
}
其中String command = "echo > 0 /sys/bus/platform/drivers/battery/Charging_switch";本来打算是应用检测到电量为100%时自动执行该命令,不让机器充电;但是实现不了,求高手解答;谢谢;
Android中调用shell命令;
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- 我用双手-成就你的梦想 2015-06-18 10:13关注
String tTempString = new String("su -c reboot");
//StandByMode = false;
int r = 0;
try {
Process process = Runtime.getRuntime().exec(tTempString);} catch (Exception e) { e.printStackTrace(); } //我写的一个重启的命令有效的
解决 无用评论 打赏 举报
悬赏问题
- ¥15 oracle集群安装出bug
- ¥15 关于#python#的问题:自动化测试
- ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
- ¥15 教务系统账号被盗号如何追溯设备
- ¥20 delta降尺度方法,未来数据怎么降尺度
- ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
- ¥15 再不同版本的系统上,TCP传输速度不一致
- ¥15 高德地图点聚合中Marker的位置无法实时更新
- ¥15 DIFY API Endpoint 问题。
- ¥20 sub地址DHCP问题