Code Monkey home page Code Monkey logo

checkversionlib's Introduction

CheckVersionLib

现在热更新技术挺火的,大公司都出了自己的热更新框架,但是各家热更新都有各自优缺点,终究不能解决所有bug,万不得已还是得进行版本升级,这是一个android上的自动版本检测并更新库。库集成了检测版本、下载版本以及自动安装升级 ##特点

  • 任何地方都可以检测

  • 任何地方都可以弹出升级对话框

  • 自定义性强,手动回调解析,适用于各种版本检测接口

  • 自动处理下载和升级

  • 自定义界面

效果

使用步骤

android studio导入

compile 'com.allenliu.versionchecklib:library:1.0.4'

如何使用

1.自定义service,service必须继承库的 AVersionService ,实现其中的 onResponses(AVersionService service, String response)抽象方法,该方法 主要是请求版本接口的回调,由于不同的使用者版本检测接口返回数据类型不一致,所以你需要自定解析数据,然后判断版本号之后调用升级对话框,如果使用库自带的直接调用如下方法: service.showVersionDialog(downloadUrl,title,updateMsg ) 示例代码:          

     if (serverVersion > clientVersion) { 
      //传入下载地址,以及版本更新消息
     service.showVersionDialog(downloadUrl,title,updateMsg );}

如果拿到数据之后,不使用库的方法,那么你可以在回调 里做自己想做的事。记得这里需要自己手动关闭service(如果调用showVersionDialog则不需要手动关闭)

2.在任意地方开启自定义service,并传入VersionParam

    `versionParams = new VersionParams().setRequestUrl("http://www.baidu.com");
    Intent intent = new Intent(this, DemoService.class);
    intent.putExtra(AVersionService.VERSION_PARAMS_KEY, versionParams);
    startService(intent);`

VersionParams有如下方法,除了requestUrl都是可选值

自定义界面

如果想自定义界面,只需创建一个继承自VersionDialogActivity的Activity,Activity设置Theme为透明:

android:theme="@style/versionCheckLibvtransparentTheme"

开启Service的时候,将自定义的Activity传入VersionParams

setCustomDownloadActivityClass(CustomVersionDialogActivity.class)

  • 自定义 版本dialog,重写 showVersionDialog() ,在里面实现自己的逻辑,最后调用downloadFile(url)或者downloadFile(url,filecallback)注意不要调用父类的方法

  • 自定义 下载中dialog,重写showLoadingDialog(int currentProgress),在里面实现自己的逻辑

  • 自定义 下载失败dialog ,重写showFailDialog,实现自己的逻辑

  • 除此之外还可以在定义的Activity里面监听一些下载和点击回调

    setOnDownloadSuccessListener(this);
    
    setCommitClickListener(this);
    
    setCancelClickListener(this);
    
    setOnDownloadingListener(this);
    

下载通知栏图标和文字替换

需要自定义图标只需在mimap文件下建立ic_launcher图标,替换标题只需在项目xml定义app_name属性,还有其他一些属性替换,如下表:

属性名 属性值
versionchecklib_confirm 确认
versionchecklib_cancel 取消
versionchecklib_retry 重试
versionchecklib_download_fail_retry 下载失败是否重试?
versionchecklib_download_finish 下载完成,点击安装
versionchecklib_downloading 正在下载中...
versionchecklib_check_new_version 检测到新版本
versionchecklib_download_fail 下载失败,点击重试
更详细的使用请看demo
欢迎star和提issue

License

    Copyright 2017 AllenLiu.

    Licensed to the Apache Software Foundation (ASF) under one or more contributor
    license agreements. See the NOTICE file distributed with this work for
    additional information regarding copyright ownership. The ASF licenses this
    file to you under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License. You may obtain a copy of
    the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    License for the specific language governing permissions and limitations under
    the License.

checkversionlib's People

Contributors

alexliusheng avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.