안드로이드 로컬 자동으로 달성하기 위해 업그레이드 OTA

면책 조항 :이 문서는 블로거 원본입니다은 허용 블로거없이 복제 할 수 없다. 무단 전재 무단 전재 https://blog.csdn.net/qq_23327993 https://blog.csdn.net/qq_23327993/article/details/89955990을 추가해야합니다

머리말

상기에서 안드로이드 로컬 자동 업그레이드에 따라 여기에 구체적으로 업그레이드 OTA 기술 여러 가지 방법으로 , 지금, 말을 많이하지 않았다 ...

본문

기반 QCOM msm8953 Android7.1.2 플랫폼입니다.
업그레이드 할 준비가 OTA 업그레이드 패키지, 우선은 여기에서 update.zip 이름. 작은 파트너를 만드는 방법을 알고하지 않았다 패키지를 업그레이드 오타, 당신은 여기에 찌를 수있다 -
여기, 우리는 업그레이드 패키지 update.zip을 가지고 assume've.
(packageFile 파일, 컨텍스트 컨텍스트) 라인 시작하고 코드, 다음,이 작업을 수행하기 위해, 당신이 우리가 전화를위한 안드로이드 시스템이 android.os.RecoverySystem 클래스에서 특히, 일부 installPackage API를 제공하는 것을 알아야한다.
이 클래스는, 많은있다 verifyPackage 방법을 아래에 넣어하는 방법, 복구 시스템이 업그레이드 패키지를 확인하는 것입니다 있지만, 업그레이드 패키지를 확인하는 데 사용되는 방법은, 여기 응용 프로그램 계층에서 업그레이드 패키지는 검증을 할 것을 권장합니다, 당신은 사전에 오류를 방지 할 수 있습니다 당신이 안드로이드 개발자 문서에 읽을 수있는 클래스의 다른 방법이 여기에 사다리 요 필요
여기에 그림 삽입 설명
여기에 그림 삽입 설명
주로보고, 여기와 코드 아래 간단한 방법이 두 가지 방법의 사용 :

공용 클래스 SdCardUpgradeProcess는 활동 RecoverySystem.ProgressListener을 {구현 확장

private static final String TAG = "SdCardUpgrade";
private static final int VERIFY_COMPLETE = 70;
private static final int INSTALL_COMPLETE  = 100;
private static String updatePath = "/data/ota_package/";
private String updateName = "";
private ProgressBar mProcessbar;
private TextView mUpdateStep;
private TextView mUpdateState;
private TextView mNotify;
private TextView sdcard_update_introduction_textview_one;
private TextView sdcard_update_introduction_textview_two;
private ImageView mCompleteImg;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sdcardupgrade_processbar);

    UpdateInfo updateInfo = getIntent().getParcelableExtra("updateInfo");
    Log.e(TAG,"name:"+updateInfo.getUpdateName());
    Log.e(TAG,"cnt:"+updateInfo.getUpdateCnt());
    updateName = updateInfo.getUpdateName();

    mUpdateStep = (TextView)findViewById(R.id.step_number);
    mUpdateState = (TextView)findViewById(R.id.processbar_title);
    mNotify = (TextView)findViewById(R.id.update_notify);
    mCompleteImg = (ImageView)findViewById(R.id.update_complete);

    mProcessbar=(ProgressBar)findViewById(R.id.processbar);
    mProcessbar.setMax(110);
    mProcessbar.setProgress(0);
    mProcessbar.setIndeterminate(false);

    runnable.start();

}
Handler mHandler = new Handler(){
    public void handleMessage(Message msg) {

        mProcessbar.setProgress(msg.arg1);

        switch(msg.arg1){
            case VERIFY_COMPLETE:
                mUpdateStep.setText(getString(R.string.the_next_step_number));
                mUpdateState.setText(getString(R.string.install_process));
                mNotify.setText("");
                break;

            case INSTALL_COMPLETE:
                mUpdateState.setText(getString(R.string.install_process_complete));
                mNotify.setText(getString(R.string.restart));
                mCompleteImg.setBackgroundResource(R.drawable.ic_launcher_background);
                break;

            default:
                break;
        }
    }
};
Thread runnable = new Thread(){

    @Override
    public void run() {
        if(null == updatePath || null == updateName)
            return;
        Log.d(TAG, "Start update .............");
        File file = new File(updatePath+updateName);
        Log.d(TAG, "file:" +file+"");
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "SdCardUpgrade ProcessBar");
        try{
            wl.acquire();//升级保持亮屏状态
            RecoverySystem.verifyPackage(file, SdCardUpgradeProcess.this, null);
            Log.d(TAG,"Verify package complete.");
            RecoverySystem.installPackage(SdCardUpgradeProcess.this, file);

        }catch(Exception e){
            Log.e(TAG, e.getMessage(), e);

        }finally{
            wl.release();
        }
    }
};

@Override
public void onProgress(int progress) {
    Log.d(TAG,"progress="+progress);
    Message msg = Message.obtain();
    msg.arg1 = progress;
    mHandler.sendMessage(msg);
}
@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    System.exit(0);
}

}

추신

전체 데모 다운로드 경로 : AndroidOtaUpdate.rar

추천

출처blog.csdn.net/qq_23327993/article/details/89955990