Skip to content

Latest commit

 

History

History
162 lines (120 loc) · 3.91 KB

README_zh.md

File metadata and controls

162 lines (120 loc) · 3.91 KB

AppUpdate

Android 检查更新库

屏幕截图

如何使用

配置

  • Step 1.配置jitpack仓库

    在根目录的gradle.build中添加jitpack地址:

    allprojects {
    	repositories {
    		...
    		maven { url 'https://jitpack.io' }
    	}
    }
  • Step 2. 添加库依赖:

    dependencies {
             compile 'com.github.fccaikai:AppUpdate:2.1.4'
     }

使用

UpdateWrapper updateWrapper = new UpdateWrapper.Builder(getApplicationContext())
    					//set interval Time
    	                .setTime(time)
    	                //set notification icon
    	                .setNotificationIcon(R.mipmap.ic_launcher_round)
    	                //set update file url
    	                .setUrl("you update json file url")
    	                //set showToast. default is true
    	                .setIsShowToast(false)
						//add callback ,return new version info
						.setCallback(new CheckUpdateTask.Callback() {
                                    @Override
                                    public void callBack(VersionModel model,boolean hasNewVersion) {
                                        Log.d(TAG,"new version :" + 																		model.getVersionName());
                                    }
                         })
						 .build();
updateWrapper.start();

升级json文件格式:

{
  "versionCode":1,
  "versionName":"1.0.0",
  "content":"1.新增抢单功能#2.性能优化",//使用 # 来进行换行
  "minSupport":1,	//最低支持版本,小于此版本必须强制更新
  "url":"apk download url"
}

自定义UI

  • 自定义Activity 创建一个Activity 继承自UpdateActivity,并重写protected Fragment getUpdateDialogFragment()方法,比如:
public class CustomsUpdateActivity extends UpdateActivity {
    @Override
    protected Fragment getUpdateDialogFragment() {
        return CustomsUpdateFragment.newInstance(mModel);
    }
}
  • 设置主题

    Activity需要设置为Dialog主题,在Androidmanifest.xml中注册Activity中设置主题

    <activity
              android:name=".CustomsUpdateActivity"
              android:theme="@style/UpdateDialog">
    </activity>

  • 自定义FragmentDialog

创建一个FragmentDialog,继承自UpdateDialog,代码如下:

public class CustomsUpdateFragment extends UpdateDialog {

  public static CustomsUpdateFragment newInstance(VersionModel model) {

      Bundle args = new Bundle();
      args.putSerializable(Constant.MODEL, model);
      CustomsUpdateFragment fragment = new CustomsUpdateFragment();
      fragment.setArguments(args);
      return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_update_dialog;
    }

    @Override
    protected void setContent(View view, int contentId) {
        super.setContent(view, R.id.content);
    }

    @Override
    protected void bindUpdateListener(View view, int updateId) {
        super.bindUpdateListener(view, R.id.update);
    }

    @Override
    protected void bindCancelListener(View view, int cancelId) {
        super.bindCancelListener(view, R.id.cancel);
    }

    @Override
    protected void initIfMustUpdate(View view, int id) {
        super.initIfMustUpdate(view, R.id.cancel);
    }
}
  • 配置
UpdateWrapper.Builder builder = ...;
builder.setCustomsActivity(CustomsUpdateActivity.class);
...
builder.build().start();

具体使用请查看demo

依赖的库

  • v7-support

    compile 'com.android.support:appcompat-v7:25.2.0'

    如果你不想使用这两个库,可以使用exclude排除