package com.anyun.exam.lib; import android.content.Context; import android.os.Build; import android.os.RecoverySystem; import android.util.Log; import java.io.File; import java.io.IOException; public class Ota { private final static String TAG = "OTA"; static String dest = "/data/media/0/update.zip"; public boolean excuteUpdateZip(Context context, String path) { boolean verifyPass = false; // TODO Auto-generated method stub try { File ota = new File(dest); Log.d(TAG, "path = " + ota.getCanonicalPath() + " " + ota.exists()); Log.d(TAG, "Product Model: " + Build.DISPLAY); try { RecoverySystem.verifyPackage(ota, recoveryVerifyListener, null); verifyPass = true; Log.d(TAG, "Verify OK"); } catch (Exception e) { verifyPass = false; Log.d(TAG, "Zip Verify Fail!"); } if (verifyPass) { RecoverySystem.installPackage(context, ota); } } catch (IOException e) { // TODO Auto-generated catch block Log.e(TAG, "OTA 错误 " + e.getMessage()); } finally { return verifyPass; } } RecoverySystem.ProgressListener recoveryVerifyListener = new RecoverySystem.ProgressListener() { public void onProgress(int progress) { Log.d(TAG, "verify progress" + progress); // final int progress1=progress; // showinfo("verify progress " + progress1+" %"); } }; }