Android uses code to enter Recovery mode to automatically upgrade the specified firmware package

From: http://blog.csdn.net/zhoumushui/article/details/50766041

Enter Recovery and automatically upgrade the upgrade package under the specified path, OTA download the firmware package to the specified path/sdcard/update.zip, and then execute the following code Enter Recovery to execute the installation:

private static File RECOVERY_DIR = new File("/cache/recovery");
private static File COMMAND_FILE = new File(RECOVERY_DIR, "command");

private static void recoveryMode(Context context) throws IOException {
String arg = "--update_package=/sdcard/update.zip";
RECOVERY_DIR.mkdirs();

FileWriter command = new FileWriter(COMMAND_FILE);
try {
command.write(arg); // write recoveryELF to /cache/recovery/command execution parameters.
command.write("\n");
} finally {
command.close();
}
PowerManager pm = (PowerManager) context
.getSystemService(Context.POWER_SERVICE);
pm.reboot("recovery"); // call reboot method in PowerManager class

throw new IOException("Reboot failed (no permissions?)");
}


Required Declare the REBOOT permission, which needs to be the system uid to invoke this permission.

    <uses-permission android:name="android.permission.REBOOT" />


General applications do not have permission, you can open the corresponding interface in the system application, and execute the above code after receiving the specified broadcast.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326079890&siteId=291194637