Skip to content

版本检测升级(更新)库。an auto check version library(app update) on Android

Notifications You must be signed in to change notification settings

jikun2008/CheckVersionLib

 
 

Repository files navigation

CheckVersionLib

V2 Version has been born with shocking, strong functions,chain programing, easy to integrate,strong extension

中文文档

The strongest feature is easier to integrate than version of V1.+

Effect

Features

  • Invoke everywhere you want

  • Easy

  • Strong Extension

  • Adapt to all applications that have update function

  • Customize Ui

  • Support Force Update(one line code)

  • Support Silence Download (one line code)

  • Adapt to Android Q

include

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

appcompat

  implementation 'com.github.AlexLiuSheng:CheckVersionLib:2.4.1_appcompat'

jitpack && android x


dependencies {
	        implementation 'com.github.AlexLiuSheng:CheckVersionLib:2.4.1_androidx'
	}

usage

Only using download mode

the easiest way to use

        AllenVersionChecker
                .getInstance()
                .downloadOnly(
                        UIData.create().setDownloadUrl(downloadUrl)
                )
                .executeMission(context);

UIData:UIData is the type of Bundle,it saves some data for displaying ui page,it can use in your customization page/

Request Version + Download mode

the easiest way to call

   AllenVersionChecker
                .getInstance()
                .requestVersion()
                .setRequestUrl(requestUrl)
                .request(new RequestVersionListener() {
                    @Nullable
                    @Override
                    public UIData onRequestVersionSuccess(String result) {
                        //get the data response from server,parse,get the `downloadUlr` and some other ui date
                      
                        ...
                        //return null if you dont want to update application
                        return UIData.create().setDownloadUrl(downloadUrl);
                    }

                    @Override
                    public void onRequestVersionFailure(String message) {

                    }
                })
                .executeMission(context);


Some other http params for request app version,as follows

 AllenVersionChecker
                .getInstance()
                .requestVersion()
                .setHttpHeaders(httpHeader)
                .setRequestMethod(HttpRequestMethod.POSTJSON)
                .setRequestParams(httpParam)
                .setRequestUrl(requestUrl)
                .request(new RequestVersionListener() {
                    @Nullable
                    @Override
                    public UIData onRequestVersionSuccess(String result) {
                        //get the data response from server,parse,get the `downloadUlr` and some other ui date
                        ...
                        UIData uiData = UIData
                                .create()
                                .setDownloadUrl(downloadUrl)
                                .setTitle(updateTitle)
                                .setContent(updateContent);
                        //return null if you dont want to update application
                        uiData.getVersionBundle().putString("key", "your value");
                        return uiData;

                    }

                    @Override
                    public void onRequestVersionFailure(String message) {

                    }
                })
                .executeMission(context);

the instructions above is the basic using for integrating(library has a set of default ui page),you can use some other params,if it does not fit your requirement the above.

cancel all mission

to avoid memory leak,It is necessary to cancel all missiones when you dont want to use library.you should put code of cancel in properly place.

 AllenVersionChecker.getInstance().cancelAllMission();

some other functions

first of all,the builder of follow is called DownloadBuilder

 DownloadBuilder builder=AllenVersionChecker
                .getInstance()
                .downloadOnly();
                
                
      or          
                
                
                
 DownloadBuilder builder=AllenVersionChecker
                 .getInstance()
                 .requestVersion()
                 .request()

cancel mission

 AllenVersionChecker.getInstance().cancelAllMission(this);

silent download

 builder.setSilentDownload(true); false for default

set the newest version code of your server returned,it is used to verify if use file cache.

  • Cache category:first check running app's versionCode whether equal with the installation package.Then check developer whether pass the newest VersionCode ,if so, check the VersionCode is greater than local,if it is truth ,download apk from server, otherwise use cache.
 builder.setNewestVersionCode(int); null for default 

Force Update

set the listener represent need force update function,it will be call when user cancel the download operation,developer need close all the activities of application.

builder.setForceUpdateListener(() -> {
              forceUpdate();
          });

update in v2.2.1 for setForceUpdateListener dynamically after server response,you can setForceUpdateListener in callback of http request,eg.

   public UIData onRequestVersionSuccess(DownloadBuilder downloadBuilder,String result) {
                          downloadBuilder.setForceUpdateListener(() -> {
                              forceUpdate();
                          });
                          Toast.makeText(V2Activity.this, "request successful", Toast.LENGTH_SHORT).show();
                          return crateUIData();
                      }

Force ReDownload no matter there is cache

 builder.setForceRedownload(true); false for default

set whether show downloading dialog

builder.setShowDownloadingDialog(false); true for default

set whether show notification

builder.setShowNotification(false);  true for default 

run as foreground service(update in 2.2.2) recomended

builder.setRunOnForegroundService(true); 默认true

customize notification

      builder.setNotificationBuilder(
                 NotificationBuilder.create()
                         .setRingtone(true)
                         .setIcon(R.mipmap.dialog4)
                         .setTicker("custom_ticker")
                         .setContentTitle("custom title")
                         .setContentText(getString(R.string.custom_content_text))
         );

set whether show download failed dialog

  builder.setShowDownloadFailDialog(false); true for default

customize download apk path

  builder.setDownloadAPKPath(address); default:/storage/emulated/0/AllenVersionPath/

customize download apk name

  builder.setApkName(apkName); default:getPackageName()

set download listener

   builder.setApkDownloadListener(new APKDownloadListener() {
             @Override
             public void onDownloading(int progress) {
                 
             }

             @Override
             public void onDownloadSuccess(File file) {

             }

             @Override
             public void onDownloadFail() {

             }
         });

cancel listener


 builder.setOnCancelListener(() -> {
            Toast.makeText(V2Activity.this,"Cancel Hanlde",Toast.LENGTH_SHORT).show();
        });

if u want to monitor the cancel operation in different state

  • builder.setDownloadingCancelListener();
  • builder.setDownloadFailedCancelListener();
  • builder.setReadyDownloadCancelListener();

set commit click listener(added after 2.2.2)

  • builder.setReadyDownloadCommitClickListener();
  • builder.setDownloadFailedCommitClickListener();

silent download+install directly(dont popup update dialog)

    builder.setDirectDownload(true);
           builder.setShowNotification(false);
           builder.setShowDownloadingDialog(false);
           builder.setShowDownloadFailDialog(false);

customize install callback

  setCustomDownloadInstallListener(CustomInstallListener customDownloadInstallListener)

customize the ui page

Customization page used the way of listener,developer need return the Dialog(parent:android.app) that you customized

  • all the dialog must initiate with the context inside the listener.

  • the data fo page takes from UIData

Customize Show Version Dialog

setCustomVersionDialogListener

  • define the page must have a commit download button,the id of button must be @id/versionchecklib_version_dialog_commit

  • if has cancel button(ignore if not),the id of button must be @id/versionchecklib_version_dialog_cancel

eg.

  builder.setCustomVersionDialogListener((context, versionBundle) -> {
            BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, R.layout.custom_dialog_one_layout);
            //versionBundle is instance of UIData,passed from developer,it can be use to display 
            TextView textView = baseDialog.findViewById(R.id.tv_msg);
            textView.setText(versionBundle.getContent());
            return baseDialog;
        });

customize downloading dialog page

setCustomDownloadingDialogListener

  • if has cancel button(ignore if not),the id of button must be@id/versionchecklib_loading_dialog_cancel
    builder.setCustomDownloadingDialogListener(new CustomDownloadingDialogListener() {
            @Override
            public Dialog getCustomDownloadingDialog(Context context, int progress, UIData versionBundle) {
                BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, R.layout.custom_download_layout);
                return baseDialog;
            }
// loop invoke the updateUI method when downloading
            @Override
            public void updateUI(Dialog dialog, int progress, UIData versionBundle) {
                TextView tvProgress = dialog.findViewById(R.id.tv_progress);
                ProgressBar progressBar = dialog.findViewById(R.id.pb);
                progressBar.setProgress(progress);
                tvProgress.setText(getString(R.string.versionchecklib_progress, progress));
            }
        });

customize download failed page

setCustomDownloadFailedListener

  • if having button of retry,the id must be@id/versionchecklib_failed_dialog_retry

  • if having the button of commit/cancel,the id must be @id/versionchecklib_failed_dialog_cancel

   builder.setCustomDownloadFailedListener((context, versionBundle) -> {
            BaseDialog baseDialog = new BaseDialog(context, R.style.BaseDialog, R.layout.custom_download_failed_dialog);
            return baseDialog;
        });

ProGuard

-keepattributes *Annotation*
-keepclassmembers class * {
    @org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
 
# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
    <init>(java.lang.Throwable);
}
 -keep class com.allenliu.versionchecklib.**{*;}

update Log

  • 2.2.1
    • fix the bugs of memory leak
    • use binder to pass params
    • some known issues

Last


  • download the demo to view more functions

  • thanks all for the support library

  • star/issue is welcome

License


Apache 2.0

About

版本检测升级(更新)库。an auto check version library(app update) on Android

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 72.3%
  • Kotlin 27.7%