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库。