AppUpdater
介绍:
一个从Google Play, GitHub, Amazon 或者 F-Droid上检查app更新的library。
运行效果:
使用说明:
Sample Project
你可以在Google Play上现在最新的 sample APK:
如何引入
把这个 repository添加到你的projectbuild.gradle中:
repositories {
maven {
url "https://jitpack.io"
}
}
把library添加到你的module build.gradle中:
dependencies {
compile 'com.github.javiersantos:AppUpdater:1.1'
}
使用
在Manifest中添加INTERNET和ACCESS_NETWORK_STATE权限:****
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Activity
AppUpdater appUpdater = new AppUpdater(this);
appUpdater.start();
Fragment
AppUpdater appUpdater = new AppUpdater(getActivity());
appUpdater.start();
自定义
Use the builder and add following:
// (Optional) Provide a Display mode.
// Default: Display.DIALOG
.setDisplay(Display.DIALOG)
.setDisplay(Display.SNACKBAR)
.setDisplay(Display.NOTIFICATION)
// (Optional) Provide a duration for the Snackbars.
// Default: Duration.NORMAL
.setDuration(Duration.NORMAL)
.setDuration(Duration.INDEFINITE)
// (Optional) Provide a source for the updates.
// Default: UpdateFrom.GOOGLE_PLAY
.setUpdateFrom(UpdateFrom.GOOGLE_PLAY)
.setUpdateFrom(UpdateFrom.GITHUB)
.setUpdateFrom(UpdateFrom.AMAZON)
.setUpdateFrom(UpdateFrom.FDROID)
// (Required for GITHUB, optional otherwise) Provide the GitHub user and repo where releases are available.
.setGitHubUserAndRepo("javiersantos", "AppUpdater")
// (Optional) Updates will be displayed only every X times the app ascertains that a new update is available.
// Default: 1 (Always)
.showEvery(5)
// (Optional) Show dialog, snackbar or notification although there aren't updates.
// Default: false
.showAppUpdated(true)
其它特性
获得最新的更新并和当前安装版本比较(异步)
AppUpdaterUtils appUpdaterUtils = new AppUpdaterUtils(this)
//.setUpdateFrom(UpdateFrom.AMAZON)
//.setUpdateFrom(UpdateFrom.FDROID)
//.setUpdateFrom(UpdateFrom.GITHUB)
//.setGitHubUserAndRepo("javiersantos", "AppUpdater")
.withListener(new AppUpdaterUtils.AppUpdaterListener() {
@Override
public void onSuccess(String latestVersion, Boolean isUpdateAvailable) {
Log.d("AppUpdater", latestVersion + ", " + Boolean.toString(isUpdateAvailable));
});
appUpdaterUtils.start();
已下载
0