从应用程序安装.zip发条?

时间:2011-02-17 20:20:16

标签: java android root

所以在我的应用程序中我试图使用此

使其在发条恢复中闪存.zip
 Runtime run = Runtime.getRuntime();
                      Process p = null;
                      DataOutputStream out = null;
                      try{
                          p = run.exec("su");
                          out = new DataOutputStream(p.getOutputStream());
                          out.writeBytes("echo install_zip SDCARD:" +clickedFile.toString() +" > /cache/recovery/extendedcommand\n");
                          out.writeBytes("reboot recovery\n"); // testing
                          out.flush();

                      }catch(Exception e){
                          Log.e("FLASH", "Unable to reboot into recovery mode:", e);
                          e.printStackTrace();

                      }

它会启动恢复,但它不会闪烁.zip ..什么是错的..哦,如果你需要整个.java文件,它是:

http://pastebin.com/NpiSLz90

2 个答案:

答案 0 :(得分:1)

out.writeBytes("echo 'install_zip(\""+ SDCARD:" +clickedFile.toString()+"\");'" +" > /cache/recovery/extendedcommand\n");

adb命令看起来像:

adb shell
echo 'install_zip("/sdcard/update.zip");' > /cache/recovery/extendedcommand

答案 1 :(得分:1)

我遇到了同样的问题,但我使用的是ListView与ArrayAdapter相结合来返回文件的完整路径。当我尝试将路径传递为'SDCARD:'后跟文件的路径时,它无法找到该文件,因为较新版本的CWM Recovery似乎不再支持该方法。我找到了一个简单的解决方法:

    public boolean installPackage(String pos) throws InterruptedException {
    final String location = "/emmc/" + pos.substring(11);
    Process process = null;
    try {
        process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("echo 'install_zip(\"" + location + "\");'" + " > /cache/recovery/extendedcommand\n");
        os.writeBytes("reboot recovery\n");
        os.writeBytes("exit\n");
        os.flush();
        return (process.waitFor() == 0);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.e("FLASH:", "Unable to boot into recovery");
        e.printStackTrace();
    }
        return false;
}