APP下载更新

1. 简介

APP下载更新,一键集成App版本升级。(无需担心通知栏适配;无需担心重复点击下载;无需担心App安装等问题;这些AppUpdater都已帮您处理好。)

1.1. 特性

  1. 专注于App更新一键傻瓜式升级
  2. 支持Android O
  3. 支持通知栏提示内容和过程全部可配置
  4. 支持下载优先取本地缓存
  5. 支持下载监听

2. 基础环境

  • AndroidStudio 3.4.+
  • java1.8
  • gradle 5.1.1

3. 如何使用

3.1. Release版本

  • 项目依赖
allprojects {
  repositories {
        maven {
               // 配置用户名和密码
               credentials {
                    username 'anonymous'
                    password ''
               }
               // 配置仓库地址
               url 'http://172.16.28.234:8083/repository/maven-releases/'
           }
  }
}
  • 添加依赖
    implementation 'com.jpxx.android.library:app-updater-support:<latest.version>'

3.2. 快照版本

  • 项目依赖
allprojects {
  repositories {
        maven {
               // 配置用户名和密码
               credentials {
                   username 'anonymous'
                   password ''
               }
               // 配置仓库地址
               url 'http://172.16.28.234:8083/repository/maven-snapshots/'
           }
  }
}
  • 添加依赖
    implementation 'com.jpxx.android.library:app-updater-support:1.0.0-SNAPSHOT'

4. 使用说明

4.1. 直接下载

val appUpdater = AppUpdater.Builder()
                    .setUrl(downloadUrl)
                    .setChannelId("app_download")
                    .setChannelName("app_download")
                    .setFilename("android_app.apk")
                    .setInstallApk(true)
                    .setDownloadAlways(true)
                    .setNotificationTitle("MikesApp")
                    .setNotificationId(0x10)
                    .setNotificationIcon(R.drawable.ic_icon_tab_chengshi_unselected)
                    .build(this@AppUpdateDemoActivity)
            appUpdater.startDownloadApk("请允许存储权限以下载更新") {apkFile ->
                if(apkFile == null){
                    ToastHelper.toastMessage("下载失败", Gravity.CENTER, DToast.DURATION_LONG)
                } else{
                    ToastHelper.toastMessage("下载成功, file : ${apkFile.absolutePath}" , Gravity.CENTER, DToast.DURATION_LONG)
                }
            }

4.2. 系统弹窗+下载

AlertDialog.Builder(this)
                    .setTitle("发现新版本")
                    .setMessage("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
                    .setPositiveButton("升级") { _, _ ->
                        AppUpdater.Builder()
                                .setUrl(downloadUrl)
                                .setDownloadAlways(true)
                                .build(this@AppUpdateDemoActivity)
                                .startDownloadApk("请允许存储权限以下载更新") {apkFile ->
                                    if(apkFile == null){
                                        ToastHelper.toastMessage("下载失败", Gravity.CENTER, DToast.DURATION_LONG)
                                    } else{
                                        ToastHelper.toastMessage("下载成功, file : ${apkFile.absolutePath}" , Gravity.CENTER, DToast.DURATION_LONG)
                                    }
                                }
                    }.show()

4.3. 简单弹窗升级

val config = AppUpdateDialogConfig()
            config.setTitle("简单弹框升级")
                    .setOk("升级")
                    .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
                    .setOnClickOk { _ ->
                        AppUpdater.Builder()
                                .setUrl(downloadUrl)
                                .setDownloadAlways(true)
                                .build(this@AppUpdateDemoActivity)
                                .startDownloadApk("请允许存储权限以下载更新") {apkFile ->
                                    if(apkFile == null){
                                        ToastHelper.toastMessage("下载失败", Gravity.CENTER, DToast.DURATION_LONG)
                                    } else{
                                        ToastHelper.toastMessage("下载成功, file : ${apkFile.absolutePath}" , Gravity.CENTER, DToast.DURATION_LONG)
                                    }
                                }

                        AppDialogUtil.INSTANCE.dismissDialog()
                    }
            AppDialogUtil.INSTANCE.showDialog(this@AppUpdateDemoActivity, config)

4.4. DialogFragment弹窗升级

val config = AppUpdateDialogConfig()
            config.setTitle("简单DialogFragment升级")
                    .setOk("升级")
                    .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
                    .setOnClickOk {
                        AppUpdater.Builder()
                                .setUrl(downloadUrl)
                                .setDownloadAlways(false)
                                .build(this@AppUpdateDemoActivity)
                                .startDownloadApk("请允许存储权限以下载更新") {apkFile ->
                                    if(apkFile == null){
                                        ToastHelper.toastMessage("下载失败", Gravity.CENTER, DToast.DURATION_LONG)
                                    } else{
                                        ToastHelper.toastMessage("下载成功, file : ${apkFile.absolutePath}" , Gravity.CENTER, DToast.DURATION_LONG)
                                    }
                                }
                        AppDialogUtil.INSTANCE.dismissDialogFragment(supportFragmentManager)
                    }
            AppDialogUtil.INSTANCE.showDialogFragment(supportFragmentManager, config)

源码地址:http://172.16.28.234:8081/dev-plat/android/lib/app-updater

源码地址:http://sources.jpsycn.com/dev-plat/android/lib/app-updater.git

Copyright © jpsycn.com 2018 all right reserved,powered by Gitbook该文件修订时间: 2019-09-10 14:26:29

results matching ""

    No results matching ""