新聞中心
apk文件怎么在Android應(yīng)用中安裝?針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。
成都創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站制作、成都網(wǎng)站建設(shè)與策劃設(shè)計(jì),宛城網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:宛城等地區(qū)。宛城做網(wǎng)站價(jià)格咨詢:18982081108
Android安裝apk文件并適配Android 7.0詳解
首先在AndroidManifest.xml文件,activity同級(jí)節(jié)點(diǎn)注冊(cè)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"?>
最后編寫代碼,區(qū)分不同Android系統(tǒng)版本號(hào),安裝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); } }
關(guān)于apk文件怎么在Android應(yīng)用中安裝問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
網(wǎng)站欄目:apk文件怎么在Android應(yīng)用中安裝
當(dāng)前地址:http://www.dlmjj.cn/article/pppisg.html