Home

Awesome

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

<img src="https://github.com/AlexLiuSheng/CheckVersionLib/blob/master/gif/v2.jpg" width=200/><img src="https://github.com/AlexLiuSheng/CheckVersionLib/blob/master/gif/V2.gif" width=200/>

Features

include

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

dependencies {
	        implementation 'com.github.AlexLiuSheng:CheckVersionLib:2.4.2'
	}

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.

 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

set commit click listener(added after 2.2.2)

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

Customize Show Version Dialog

setCustomVersionDialogListener

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

    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

   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

Last


License


Apache 2.0