日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 9.x 实现应用内更新安装

發布時間:2025/4/16 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 9.x 实现应用内更新安装 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

折騰了3天,總算解決了問題。

依賴如下

implementation 'androidx.core:core:1.0.2'
// implementation 'com.android.support:support-compat:28.0.0'
support包,試了幾個版本總是提示一堆 Duplicate class android.support.v4. ……
切換到依賴 androidx,則不能忘記在 androidManifest.xml中替換 name值 <uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.INTENT" /><uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /><applicationandroid:theme="@style/AppTheme"android:networkSecurityConfig="@xml/network_security_config"><activity android:name=".UpdateActivity" /><provider android:authorities= "${applicationId}.fileprovider"android:name="androidx.core.content.FileProvider"android:exported="false"android:grantUriPermissions="true" ><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/filepath" /></provider></application>

工具類如下

public static void installApk(Activity activity, File apkFile){Intent intent =new Intent();intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//Uri uri = Uri.fromFile(apkFile);Uri uri = null;//todo N FileProvider//todo O install permissionif(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){uri = androidx.core.content.FileProvider.getUriForFile(activity,activity.getPackageName()+".fileprovider", apkFile);intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);}else{uri = Uri.fromFile(apkFile);}intent.setDataAndType(uri, "application/vnd.android.package-archive");activity.startActivity(intent);}

另外為了單純一點,避免錯誤提示

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1) Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)Go to the documentation to learn how to Fix dependency resolution errors.

解決辦法為,在gradle.properties中添加如下代碼

android.useAndroidX=true android.enableJetifier=true

最后貼一下?androidManifest.xml中提到的2個xml文件,在res/xml文件夾下

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?> <network-security-config><base-config cleartextTrafficPermitted="true" /> </network-security-config>

filepath.xml

<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"><root-path name="root" path="." /><files-path name="files" path="." /><external-path name="external" path="." /><external-cache-path name="external_cache" path="." /><external-files-path name="external_file" path="." /> </paths>

?

轉載于:https://www.cnblogs.com/htsky/p/11404946.html

總結

以上是生活随笔為你收集整理的android 9.x 实现应用内更新安装的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。