Android Library that checks for updates on Google Play, GitHub, Amazon, F-Droid or your own server. This library notifies your apps' updates by showing a Material dialog, Snackbar or notification. Check out the wiki.
You can download the latest sample APK from Google Play:
Add the repository to your project build.gradle:
repositories {
maven {
url "https://jitpack.io"
}
}
And add the library to your module build.gradle:
dependencies {
compile 'com.github.javiersantos:AppUpdater:2.5.1'
}
Add INTERNET and ACCESS_NETWORK_STATE permissions to your app's Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
By default, the basic usage will show a default dialog when a new version is found on the Play Store (otherwise nothing will be shown). By calling the .start()
method, the library will work in background. You can cancel it at any time by calling .stop()
. Other customizations are explained below.
AppUpdater appUpdater = new AppUpdater(this);
appUpdater.start();
AppUpdater appUpdater = new AppUpdater(getActivity());
appUpdater.start();
Customizations (Wiki)
The default usage is configured to display a dialog. However, there are other ways to show the update notice.
new AppUpdater(this)
.setDisplay(Display.SNACKBAR)
.setDisplay(Display.DIALOG)
.setDisplay(Display.NOTIFICATION)
...
When using the Snackbar, you can change the duration by using .setDuration(Duration.NORMAL)
(default) or
.setDuration(Duration.INDEFINITE)
.
By default the library will check for updates on the Play Store. However, there are other alternatives, such as GitHub, Amazon, F-Droid or using your own server.
new AppUpdater(this)
.setUpdateFrom(UpdateFrom.GITHUB)
.setUpdateFrom(UpdateFrom.GOOGLE_PLAY)
.setUpdateFrom(UpdateFrom.AMAZON)
.setUpdateFrom(UpdateFrom.FDROID)
.setUpdateFrom(UpdateFrom.XML)
.setUpdateFrom(UpdateFrom.JSON)
...
When using GitHub you must provide the repo where the library will check for updates: .setGitHubUserAndRepo("javiersantos", "AppUpdater")
. Check out the wiki for more details.
When using the XML source you must upload a .xml file somewhere on the Internet following the structure explained in the wiki and add the URL as shown in this example: .setUpdateXML("https://raw.githubusercontent.com/javiersantos/AppUpdater/master/app/update-changelog.xml")
.
When using the JSON source you must upload a .json file somewhere on the Internet following the structure explained in the wiki and add the URL as shown in this example: .setUpdateJSON("https://github.com/javiersantos/AppUpdater/wiki/UpdateFrom.JSON")
.
A detailed description with examples is available at: https://github.com/javiersantos/AppUpdater/wiki
By default, a dialog/Snackbar/notification will be shown whenever a new version is found. However, this can be set to show only every X times that the app ascertains that a new update is available.
new AppUpdater(this)
.showEvery(5)
...
You can also show the dialog, Snackbar or notification although there aren't updates by using .showAppUpdated(true)
(disabled by default).
new AppUpdater(this)
.setTitleOnUpdateAvailable("Update available")
.setContentOnUpdateAvailable("Check out the latest version available of my app!")
.setTitleOnUpdateNotAvailable("Update not available")
.setContentOnUpdateNotAvailable("No update available. Check for updates again later!")
.setButtonUpdate("Update now?")
.setButtonDismiss("Maybe later")
.setButtonDoNotShowAgain("Huh, not interested")
.setIcon(R.drawable.ic_update) // Notification icon
...
AppUpdaterUtils appUpdaterUtils = new AppUpdaterUtils(this)
//.setUpdateFrom(UpdateFrom.AMAZON)
//.setUpdateFrom(UpdateFrom.GITHUB)
//.setGitHubUserAndRepo("javiersantos", "AppUpdater")
//...
.withListener(new AppUpdaterUtils.UpdateListener() {
@Override
public void onSuccess(Update update, Boolean isUpdateAvailable) {
Log.d("AppUpdater", update.getLatestVersion() + ", " + update.getUrlToDownload() + ", " + Boolean.toString(isUpdateAvailable));
}
@Override
public void onFailed(AppUpdaterError error) {
Log.d("AppUpdater", "Something went wrong");
}
});
appUpdaterUtils.start();
Copyright 2016 Javier Santos
Licensed 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.