[英]Can I make an android application that should turn my phone off automatically when the user has passed a certain deadline?
I am working on a project and still thinking if it can work to make an android application that should turn the phone completely off when the user has passed a certain deadline. 我正在研究一个项目,但仍在思考是否可以制作一个Android应用程序,该应用程序应在用户超过一定期限后完全关闭手机。 and even if the user reset his settings the application still working.
即使用户重置了自己的设置,该应用程序仍然可以正常运行。 is it possible to do something like this ?
有可能做这样的事情吗?
Thanks. 谢谢。
It will work ( if rooted )... 它将工作( 如果扎根 )...
call 呼叫
runRootCmd("reboot -p"); // "-p" will power off
method: 方法:
public static void runRootCmd(String cmd) {
if (TextUtils.isEmpty(cmd)) {
return;
}
Process process;
try {
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(
process.getOutputStream());
os.writeBytes(cmd + " ;\n");
os.flush();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int read;
InputStream errIs = process.getErrorStream();
while ((read = errIs.read()) != -1) {
baos.write(read);
}
baos.write('\n');
InputStream inIs = process.getInputStream();
while ((read = inIs.read()) != -1) {
baos.write(read);
}
byte[] data = baos.toByteArray();
String result = new String(data);
Log.d(TAG, "runRootCmd result: " + result);
} catch (IOException e) {
e.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.