File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed
updateapputils/src/main/java Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,15 @@ implementation 'com.teprinciple:updateapputilsX:2.0.0'
103103 UpdateAppUtils内置了两套UI,你可以通过修改[ UiConfig] ( #UiConfig ) 进行UI内容的自定义;
104104 当然当内部UI模板与你期望UI差别很大时,你可以采用[ 完全自定义UI] ( https://github.com/teprinciple/UpdateAppUtils/blob/master/readme/%E8%87%AA%E5%AE%9A%E4%B9%89UI.md )
105105
106+ #### 5、删除已安装APK
107+ UpdateAppUtils在应用启动时,通过对比当前应用和已下载apk的VersionCode是否相同来判断已下载apk是否已安装;
108+ 如果两者VersionCode相同则认为apk已经安装,应被删除。
109+
110+ ```
111+ // 在Application或者MainActivity中调用,以达到安装成功启动后删除已安装apk
112+ UpdateAppUtils.getInstance().deleteInstalledApk()
113+ ```
114+
106115### Api说明
107116#### 1、UpdateAppUtils Api
108117
@@ -117,6 +126,7 @@ implementation 'com.teprinciple:updateapputilsX:2.0.0'
117126| fun setUpdateDownloadListener() | 下载过程监听 | null | false |
118127| fun setMd5CheckResultListener() | md5校验结果回调 | null | false |
119128| fun setOnInitUiListener() | 初始化更新弹窗UI回调 | null | false |
129+ | fun deleteInstalledApk() | 删除已安装的apk | - | false |
120130
121131#### 2、UpdateConfig:更新配置说明
122132
Original file line number Diff line number Diff line change 11package update
22
3+ import extension.log
34import extension.no
45import extension.yes
56import listener.Md5CheckResultListener
@@ -117,10 +118,13 @@ object UpdateAppUtils {
117118 /* *
118119 * 删除已安装 apk
119120 */
120- fun deleteInstalledApk (){
121- val apkPath = SPUtil .getString(DownloadAppUtils .KEY_OF_SP_APK_PATH )
122- (apkPath.isNotEmpty() && Utils .getAPPVersionCode() == Utils .getApkVersionCode(apkPath) &&
123- Utils .getApkVersionCode(apkPath) > 0 ).yes {
121+ fun deleteInstalledApk () {
122+ val apkPath = SPUtil .getString(DownloadAppUtils .KEY_OF_SP_APK_PATH , " " )
123+ val appVersionCode = Utils .getAPPVersionCode()
124+ val apkVersionCode = Utils .getApkVersionCode(apkPath)
125+ log(" appVersionCode:$appVersionCode " )
126+ log(" apkVersionCode:$apkVersionCode " )
127+ (apkPath.isNotEmpty() && appVersionCode == apkVersionCode && apkVersionCode > 0 ).yes {
124128 Utils .deleteFile(apkPath)
125129 }
126130 }
@@ -129,5 +133,5 @@ object UpdateAppUtils {
129133 * 获取单例对象
130134 */
131135 @JvmStatic
132- fun getInstance () = this
136+ fun getInstance ()= this
133137}
Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ internal object Utils {
121121 try {
122122 (file.isFile).yes {
123123 file.delete()
124+ log(" 删除成功" )
124125 }
125126 } catch (e: Exception ) {
126127 log(e.message)
You can’t perform that action at this time.
0 commit comments