日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

Android安裝apk文件并適配Android 安卓怎么安裝apk文件


Android安裝apk文件并適配Android 安卓怎么安裝apk文件


Android安裝apk文件并適配Android 7.0詳解
首先在AndroidManifest.xml文件 , activity同級節(jié)點(diǎn)注冊provider:
<providerandroid:name="android.support.v4.content.FileProvider"android:authorities="${applicationId}.file_provider"android:exported="false"android:grantUriPermissions="true"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/file_paths" /></provider>將apk文件下載到此路徑:
String cachePath = (getExternalFilesDir("upgrade_apk") +File.separator +getPackageName() +".apk");在res目錄xml文件夾下創(chuàng)建名為file_paths的文件:upgrade_apk代表上面保存路徑的文件夾名稱 , 可隨意更改 , 相同即可 。
<?xml version="1.0" encoding="utf-8"?><paths><external-files-path name="bga_upgrade_apk" path="upgrade_apk" /></paths>【Android安裝apk文件并適配Android 安卓怎么安裝apk文件】最后編寫代碼 , 區(qū)分不同Android系統(tǒng)版本號 , 安裝apk(注意:【com.apkinstall.demo】要替換自己應(yīng)用的包名)
/*** 安裝 apk 文件** @param apkFile*/public void installApk(File apkFile) {Intent installApkIntent = new Intent();installApkIntent.setAction(Intent.ACTION_VIEW);installApkIntent.addCategory(Intent.CATEGORY_DEFAULT);installApkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {installApkIntent.setDataAndType(FileProvider.getUriForFile(getApplicationContext(), "com.apkinstall.demo.file_provider", apkFile), "application/vnd.android.package-archive");installApkIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);} else {installApkIntent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");}if (getPackageManager().queryIntentActivities(installApkIntent, 0).size() > 0) {startActivity(installApkIntent);}}

    推薦閱讀