All Projects → caoyanglee → SilentUpdate

caoyanglee / SilentUpdate

Licence: MIT license
⤴️基于Kotlin的静默更新应用库 A library silently & automatically download latest apk to update your App

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to SilentUpdate

Android-LDoS
No description or website provided.
Stars: ✭ 15 (+0%)
Mutual labels:  android11
hat-view
Allow to put "hat" on TextView. Inspired by Telegram appbar title with Santa Claus hat 🎅🏻
Stars: ✭ 51 (+240%)
Mutual labels:  androidx-library
Lifecycle-Coroutines-Extension
AAC 的 Lifecycle 结合 Kotlin Coroutines 进行使用
Stars: ✭ 47 (+213.33%)
Mutual labels:  androidx-library
updater
Simple web-hook based receiver executing things via HTTP request
Stars: ✭ 77 (+413.33%)
Mutual labels:  update-service
PATCH
The PATCH repository for issues tracking, wiki and shared material.
Stars: ✭ 34 (+126.67%)
Mutual labels:  update-service
MyLogLibrary
🚧 - Simple Android Kotlin logger (2017/2020)
Stars: ✭ 31 (+106.67%)
Mutual labels:  androidx-library
Xxpermissions
Android 权限请求框架,已适配 Android 12
Stars: ✭ 2,971 (+19706.67%)
Mutual labels:  android11
Toastutils
Android 吐司框架,专治 Toast 各种疑难杂症
Stars: ✭ 2,087 (+13813.33%)
Mutual labels:  android11
flamegapps
The main repository of FlameGApps Project
Stars: ✭ 21 (+40%)
Mutual labels:  android11

静默更新应用库

License API

注意:此库是由kotlin编写而成

A library silently & automatically download latest apk to update your App
静默自动下载最新apk并升级应用

演示

双策略执行步骤

  1. 判断权限【使用者实现】
  2. 获取下载链接,判断版本号【使用者实现】
  3. 开始下载前,判断升级文件是否存在,存在:显示安装文件Dialog和回调(onFileIsExist)

一:Wifi的情况【静默】

  1. 下载时,是静默状态,不会有通知栏显示进度
  2. 下载完成,接收回调(onDownLoadSuccess),显示Notification和Dialog
  3. 用户点击DownloadSuccessDialog或Notification即跳转到安装界面

二:流量的情况【用户自行操作】

  1. 显示更新app的UpdateDialog,用户点击更新后,开始下载操作
  2. 下载时,通知栏会显示下载进度
  3. 下载完成后,接收回调(onDownLoadSuccess)并跳转安装界面

准备工作

1.获取依赖

project的build.gradle

allprojects {
    repositories {
        ......        
        maven { url 'https://jitpack.io' }
    }
}

app的build.gradle

注意:默认使用kotlin 1.4.21版本的库

implementation 'com.github.caoyanglee:SilentUpdate:{latestVersion}'

2.增加权限

<!-- 链接网络 -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- 检查网络状态 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- 存储权限 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- 通知权限 -->
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<!-- 兼容8.0 -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

3.增加FileProvider【适配7.0】

注意:此处的android:resource="@xml/filepaths"自己谷歌或直接获取demo文件

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/filepaths" />
</provider>

注意:以下为Kotlin的操作,若使用Java请点击这里

4.在Application中进行初始化

SilentUpdate.init(this)

用法

注意:
apkUrl:服务器提供的apk下载地址
latestVersion:服务器返回客户端的最新版本号
title:提示的标题
msg:提示的内容
isForce:是否强制
extra:通过extra携带更多数据

SilentUpdate.update {
    this.apkUrl = it.apkUrl
    this.latestVersion = it.latestVersion
    this.title ="这是自定义的标题"
    this.msg = "这是自定义的消息"
    this.isForce = true
    this.extra = hashMapOf<String,Any>()
}

自定义配置

1.设置提示Dialog的时间间隔

SilentUpdate.intervalDay = 7//不设置的话,默认7天

2.替换默认的弹窗

注意:执行下载任务之前都会判断更新文件是否存在,流量模式是调用下载Dialog,流量模式,文件已存在的情况是调用安装Dialog

很多时候下载Dialog和安装Dialog的样式是一样的,所以可以共用一个DialogTipAction :)

//下载提示 -> 流量模式
SilentUpdate.downLoadDialogShowAction = object : DialogShowAction {
    override fun show(context: ContextWrapper, updateContent: String, positiveClick: () -> Unit, negativeClick: () -> Unit) {
        AlertDialog.Builder(context)
                .setCancelable(false)
                .setTitle("提示")
                .setMessage("下载提示弹窗 自定义 $updateContent")
                .setPositiveButton("立即更新") { dialog, which -> positiveClick() }
                .setNegativeButton("稍后") { dialog, which -> negativeClick() }
                .show()
    }

}
//安装提示 -> 无线模式,文件已存在
SilentUpdate.installDialogShowAction = object : DialogShowAction {
    override fun show(context: ContextWrapper, updateContent: String, positiveClick: () -> Unit, negativeClick: () -> Unit) {
        AlertDialog.Builder(context)
                .setCancelable(false)
                .setTitle("提示")
                .setMessage("安装提示弹窗 自定义 $updateContent")
                .setPositiveButton("立即安装") { dialog, which -> positiveClick() }
                .setNegativeButton("稍后") { dialog, which -> negativeClick() }
                .show()
    }
}

解析包错误,无法安装

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true"
        tools:replace="android:authorities">

    <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths"
            tools:replace="android:resource" />

有的项目必须增加tools:replace="android:authorities"tools:replace="android:resource"

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].