我在机器人上安装了一个android平板电脑,它有独立的蓄电池,当蓄电池放电时,我需要关闭平板电脑的电源。有没有办法在android应用中做到这一点?如果需要,我可以启动设备。
更新-平板电脑-宏碁Iconia A100,ICS。
UPD2
下面是可用的代码
try {
Process process = new ProcessBuilder()
.command("/system/bin/su")
.start();
OutputStream o =process.getOutputStream();
o.write("/system/bin/reboot -p\n".getBytes());
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "fail!", Toast.LENGTH_LONG).show();
}发布于 2012-08-09 20:56:40
这样的东西怎么样(它只能在有根的设备上工作):
try {
// it's possible you'd have to provide full path to rebot here (ex. '/system/bin/reboot -p' ??)
Runtime.getRuntime().exec("reboot -p");
} catch( Exception e ) { // pokemon catching
}完整的工作示例(更新):
try {
// if that's not working use '/system/bin/su' instead
Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot -p"});
} catch( Exception e ) { }https://stackoverflow.com/questions/11881890
复制相似问题