Skip to content

Latest commit

 

History

History
207 lines (160 loc) · 10.9 KB

File metadata and controls

207 lines (160 loc) · 10.9 KB

Written in front

The library supports Chinese/English (other languages only need to take the same name in the corresponding string.xml)

Internal dialog background image, button support customization

To view the Log in the library, you only need to filter the tag at the beginning of AppUpdate

Focus: If downloadPath is empty, the default is getExternalCacheDir() directory, and the [storage] permission will not be request!

Table of Contents

  • Rendering
  • Function introduction
  • DownloadManager
  • UpdateConfiguration
  • Steps for usage
  • Demo download experience
  • Version update record
  • Conclusion

Rendering

     

Function introduction

  • Support AndroidX
  • Support breakpoint download
  • Support background download
  • Support for custom download process
  • Support Device >= Android M Dynamic Access Request
  • Support notification progress display (or custom display progress)
  • Support Android N
  • Support Android O
  • Support Android P
  • Support Chinese/English
  • Support for custom built-in dialog styles
  • Support for canceling the download (if the notification bar message is sent, it will be removed)
  • Support download completion Delete old APK file after opening new version
  • Download using HttpURLConnection, no other third-party framework is integrated

More detailed documentation see here《AppUpdate API Doc》

DownloadManager:Configuration Doc

Initial useDownloadManager.getInstance(this)

Attributes Description Default Value Must be set
context Context null true
apkUrl Apk download Url null true
apkName Apk download name null true
downloadPath apk download path getExternalCacheDir() false
showNewerToast Whether to prompt the user
"currently the latest version" toast
false false
smallIcon Notification icon (resource id) -1 true
configuration Additional configuration of this library null false
apkVersionCode new apk versionCode
(If set, the version will be judged in the library,
The following properties also need to be set)
1 false
apkVersionName new apk versionName null false
apkDescription Update description null false
apkSize New version of the apk size (unit M) null false
authorities Support Android N uri license package Name false

UpdateConfiguration:Configuration Doc

Attributes Description Default Value
notifyId notification id 1011
notificationChannel Adapt to Android O notifications See the source for details
httpManager Set up your own download process null
breakpointDownload Whether need to support breakpoint downloads true
enableLog Whether need to log output true
onDownloadListener Callback of the download process null
jumpInstallPage Whether the download completes automatically
pops up the installation page
true
showNotification Whether to display the progress of the
notification bar (background download toast)
true
forcedUpgrade Whether to force an upgrade false
showBgdToast Whether need to “Downloading new version in the background…” true
onButtonClickListener Button click event listener null
dialogImage Dialog background image resource
(picture specification reference demo)
-1
dialogButtonColor The color of the dialog button -1
dialogButtonTextColor The text color of the dialog button -1

All versions:Click to view

Steps for usage

Step1: app/build.gradle Dependent

implementation 'com.azhon:appupdate:2.1.0'
  • If you are using AndroidX, please implementation appupdateX
implementation 'com.azhon:appupdateX:2.1.0'

Step2:Create DownloadManager,For more usage, please see sample code here

DownloadManager manager = DownloadManager.getInstance(this);
manager.setApkName("appupdate.apk")
        .setApkUrl("https://raw.githubusercontent.com/azhon/AppUpdate/master/apk/appupdate.apk")
        .setSmallIcon(R.mipmap.ic_launcher)
        //可设置,可不设置
        .setConfiguration(configuration)
        .download();

Step3:Compatible with Android N and above,Add the following code to your app's Manifest.xml

The authorities value set in the provider must be the same as the authorities set in the DownloadManager (the application package name is not set)

android:authorities="${applicationId}"

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths_public" />
</provider>
  • If you implementation the appupdateX version

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

Step4:Resource file res/xml/file_paths_public.xml content

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path
        name="app_update_external"
        path="/" />
    <external-cache-path
        name="app_update_cache"
        path="/" />
</paths>

Step5:Cancel the download, cancel the download and continue downloading. Please refer to the Step2 of the document

private DownloadManager manager;
//取消下载
manager.cancel();

Download completed Delete old APK file after opening new version

//旧版本apk的文件保存地址
boolean b = ApkUtil.deleteOldApk(this, getExternalCacheDir().getPath() + "/appupdate.apk");
  • Compatible with Android O and above, you need to set NotificationChannel; the library has been written to go to viewNotificationUtil.java
  • Tips: The contents of the upgrade dialog can be swiped up and down!
  • If you need to implement your own set of download process, you only need to extends BaseHttpDownloadManager and update the progress with listener.
public class MyDownload extends BaseHttpDownloadManager {}

Demo download experience

Click to download Demo to experience

Version update record

  • v2.1.0
    • Added "Downloading new version in the background…" Toast switch
    • Added support for AndroidX

Conclusion

  • If you encounter problems during use, please feel free to ask Issues.