1. 程式人生 > >安卓APP版本更新及自動開啟

安卓APP版本更新及自動開啟

安卓APP自動更新版本功能及安裝完成後自動開啟

專案中要求有更新檢查最新版本的功能,功能實現後,發現新版本APP下載安裝後就結束了,沒有重新啟動,客戶還以為是閃退了,後來才發現原來是安裝過程太快了。於是,就要加上一個安裝完成後自動開啟的功能。網上查了很多以後,才發現,原來在程式碼裡就少了一句話:

/*
 * 安裝apk
 */
protected void installApk(File file) {
    Intent intent = new Intent();

    //執行動作
    intent.setAction(Intent.ACTION_VIEW);

    //執行的資料型別
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); //關鍵點: //安裝完成後執行開啟 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); }