1. 程式人生 > >android app應用內更新

android app應用內更新

1.表現形式:下載完成後會自動彈出安裝介面。已適配7.0.


2.github 地址 https://github.com/hunanqi/HNQApkInstall

3.使用方式:

  (1)在專案的的gradle檔案中加上:

  maven { url 'https://jitpack.io' }

allprojects {
    repositories {
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}


(2)在app的gradle中加上:

compile 'com.github.hunanqi:HNQApkInstall:1.0.0'

(3)在activity中:
  Intent intent = new Intent(MainActivity.this, DownApkIntentService.class);
                Bundle bundle = new Bundle();
                bundle.putString(DownApkConstant.URL, "http://imtt.dd.qq.com/16891/F93BBCA5868A3D335CF3DE847C8B4687.apk?fsname=com.tianxia.hnq.erweima_1.0_1.apk&csr=1bbd");
                bundle.putString(DownApkConstant.NAME, "sss.apk");
                bundle.putInt(DownApkConstant.IMAGE_ID, R.mipmap.ic_launcher);
                bundle.putString(DownApkConstant.TITLE, "應用更新");
                intent.putExtras(bundle);
                startService(intent);
上面需要的引數依次是:apk下載的網路地址,apk下載在本地的名字,通知欄的圖示,通知欄的標題。

4.下載後的app 地址:getExternalCacheDir()+"/"+通過ointent傳過來的name,如上sss.apk

5.關於原理:

   採用intentservice下載,handler傳送通知。

6.關於適配:此處採用應用的快取地址,故不需要讀寫儲存卡許可權,亦不需要動態申請許可權。

                        7.0應用內分享,已在moudle中使用FileProvider。服務已在moudle中註冊。自己工程只需要整合該moudle庫。