gpt4 book ai didi

android - 如何以编程方式关闭 Android 4.0 root 设备

转载 作者:太空狗 更新时间:2023-10-29 13:30:27 25 4
gpt4 key购买 nike

请帮助我找到解决方案,我知道有很多问题和重复的问题,但在这里我描述了我尝试过的所有事情。

我有一台安装了 4.0 版 android 的 android 设备。我想使用我的一个演示应用程序关闭此设备。

1) Demo application is signed by platform keys which are used in built in file system.
2) Device is already rooted as its development board and i have all permissions on this.

应用程序包含以下内容

1) Application is system application
2) Application signed by platform keys which are used in built in file system.

为了使自动化更容易,我确实将 key/cert 对导入到我的 java keystore 文件中,使用这个 keytool-importkeypair并使用 eclipse 进行签名。

下面提到了使用的命令。

命令: keytool-importkeypair -k ~/Desktop/myown.keystore -p android -pk8 platform.pk8 -cert platform.x509.pem -alias platform

我使用以下代码进行重启,但我从未在这方面取得成功。我在 stackoverflow 上阅读了很多问题和答案,但他们都说你需要

1) root access of device
2) signed apk with any one keys which are available on `build/target/product/security/`
3) Given Proper permission in AndroidManifest.xml file.

我的分数是否正确?

申请代码:

第一次尝试

public static void shutdown2() {

Runtime runtime = Runtime.getRuntime();
Process proc = null;
OutputStreamWriter osw = null;

String command = "/system/bin/reboot -p";

try { // Run Script

proc = runtime.exec("/system/xbin/su");
osw = new OutputStreamWriter(proc.getOutputStream());
osw.write(command);
osw.flush();
osw.close();

} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
if (proc != null)
proc.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (proc.exitValue() != 0) {
}
}

第二次尝试:

private void shutdown3() {
try {

String[] cmd = { "/system/bin/sh","su","reboot -p"};

Process proc = Runtime.getRuntime().exec(cmd);
proc.waitFor();
} catch (Exception ex) {
Log.i("TAG", "Could not reboot 3 ", ex);
}
}

第三次尝试:

private void shutdown() {
try {
Process proc = Runtime.getRuntime().exec(
new String[] { "/system/bin/su", "-c",
"/system/bin/reboot -p" });
proc.waitFor();
} catch (Exception ex) {
Log.i("TAG", "Could not reboot 1 ", ex);
}
}

在第三种方法中,我也尝试了 "/system/bin/su"

最佳答案

下面的代码对我有用

        Process process = Runtime.getRuntime()
.exec(new String[]{ "su", "-c", "busybox poweroff -f"});
process.waitFor();

关于android - 如何以编程方式关闭 Android 4.0 root 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16082416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com