Android 检查更新库
Step 1.配置 jitpack 仓库
在根目录的gradle.build
中添加 jitpack 地址:
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
Step 2. 添加库依赖:
dependencies { compile 'com.github.fccaikai:AppUpdate:2.0.1' }
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").build(); updateWrapper.start();
升级 json 文件格式:
{ "versionCode":1, "versionName":"1.0.0", "content":"1.新增抢单功能#2.性能优化",//使用 # 来进行换行 "mustUpdate":true, //是否强制 ,true or false "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 中设置主题
<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
compile 'com.android.support:appcompat-v7:25.2.0'
如果你不想使用这两个库,可以使用exclude
排除
源码地址:AppUpdate
![]() | 1 choury 2017-07-07 13:30:05 +08:00 ![]() 应用内更新,深恶痛绝 |
2 qq1455018613 2017-07-07 14:01:17 +08:00 应用内更新 |
![]() | 3 also24 2017-07-07 14:06:03 +08:00 |
![]() | 6 030 2017-07-07 14:30:38 +08:00 @ck19920702 所以不上 google play 为什么要装?(自己 build 的除外 |
![]() | 8 shoaly 2017-07-07 14:47:38 +08:00 有一个已经有的轮子了 前两天还在用 anyversion |