有没有办法通过编程禁用android设备?
我有一个android平板电脑安装在一个机器人,它有单独的累加器,我需要关闭平板电脑时,该蓄电池放电。 有什么办法可以从android应用程序中做到这一点? 我可以根据需要对设备进行根目录。有没有办法通过编程禁用android设备?
UPD - 平板电脑 - 宏基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();
}
如何类似的东西(这将在已解锁装置只工作):
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) { }
是的,重新启动工作!我不知道-p属性会关闭设备( – Raiv 2012-08-09 12:59:30
我在终端模拟器中测试了重启,并且一切正常,但是如果我调用Runtime.exec(“reboot -p”),它会挂起创建的进程... Runtime.exec (“su”)正常工作 – Raiv 2012-08-09 17:23:20
是的,因为你必须先打电话给su,我已经用完整的解决方案更新了我的答案:)它的工作原理,我只是检查它,你必须授予应用程序许可并记住它们在每个设备上,这样的过程可以完全自动化:) – meeDamian 2012-08-09 19:06:07
究竟是什么你的意思是禁用? – meeDamian 2012-08-09 11:31:29
我的意思是关闭电源 – Raiv 2012-08-09 12:41:45
你也许可以用Tasker做到这一点,这可能会更容易,但也意味着你可以通过编程来做到这一点。 – Stieffers 2012-08-09 12:49:04