Android 检查更新库


在根目录的gradle.build中添加jitpack地址:
groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
groovy
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"
}
UpdateActivity,并重写protected Fragment getUpdateDialogFragment()方法,比如:public class CustomsUpdateActivity extends UpdateActivity {
@Override
protected Fragment getUpdateDialogFragment() {
return CustomsUpdateFragment.newInstance(mModel);
}
}
+ 设置主题
Activity需要设置为Dialog主题,在Androidmanifest.xml中注册Activity中设置主题
xml
<activity
android:name=".CustomsUpdateActivity"
android:theme="@style/UpdateDialog">
</activity>
创建一个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
compile 'com.android.support:appcompat-v7:25.2.0'
如果你不想使用这两个库,可以使用exclude排除
$ claude mcp add AppUpdate \
-- python -m otcore.mcp_server <graph>