Install .zip in clockwork from app?

2019-02-21 04:00发布

So in my app Im trying to make it flash a .zip in clockwork recovery using this

 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();

                      }

It will boot into recovery but it will not flash the .zip.. Whats wrong.. oh, and if you need the whole .java file here it is:

http://pastebin.com/NpiSLz90

2条回答
一纸荒年 Trace。
2楼-- · 2019-02-21 04:46

I had the same issue but I was using a ListView combined with an ArrayAdapter to return the full path of the file. When I tried passing the path as 'SDCARD:' followed by the path to the file, it wasn't able to find the file as the method seems to be no longer supported by newer versions of CWM Recovery. I found an easy workaround though:

    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;
}
查看更多
萌系小妹纸
3楼-- · 2019-02-21 05:05
out.writeBytes("echo 'install_zip(\""+ SDCARD:" +clickedFile.toString()+"\");'" +" > /cache/recovery/extendedcommand\n");

adb commands would look like:

adb shell
echo 'install_zip("/sdcard/update.zip");' > /cache/recovery/extendedcommand
查看更多
登录 后发表回答