1 Star 1 Fork 0

jerry / CheckVersionLib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

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

空文件

简介

版本检测升级(更新)库。an auto check version library(app update) on Android 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/jerry_ee/CheckVersionLib.git
git@gitee.com:jerry_ee/CheckVersionLib.git
jerry_ee
CheckVersionLib
CheckVersionLib
master

搜索帮助