- Customizeable
- Easy to implement
- JSON-based checker
- Can download app
- Can auto install app
- Automatically check for updates
- Lightweight library
- Uses Google's Gson Library for easier json parsing
- Clone this repo to your device
git clone https://github.com/SnoopyCodeX/jsonupdatecheckerandroid
- After cloning, copy the folder named
cdph_updatechecker_lib
to your project's directory then include it in your app level build.gradle
compile project(':cdph_updatechecker_lib')
- Add this jar file to your app's libs directory
- (Unstable) UpdateChecker - v22.0.0
UpdateChecker checker = UpdateChecker.getInstance(context);
checker.setJsonModel(MyModel.class);
public class MyModel
{
@SerializedName("description")
List<String> description;
@SerializedName("name")
String name;
@SerializedName("version")
String version;
@SerializedName("downloadUrl")
String downloadUrl;
}
{
"name": "Test App",
"version": "1.2.0",
"description": ["My description", "Test description"],
"downloadUrl": "https://testurl.com/download"
}
checker.shouldAutoRun(true);
checker.shouldCheckUpdateOnWifiOnly(false);
checker.shouldAutoInstall(true);
checker.setUpdateLogsUrl("https://urlhere");
//Returns the filepath of the downloaded app
UpdateChecker.downloadUpdate("https://urlHere", "filename.apk");
UpdateChecker.installApp(file);
checker.setOnUpdateDetectedListener(new UpdateChecker.OnUpdateDetectedListener() {
@Override
public void onUpdateDetected(Object info)
{}
});
UpdateChecker.getInstance(this)
.setUpdateLogsUrl("https://pastebin.com/raw/x9JufEML")
.shouldAutoRun(true)
.shouldAutoInstall(false)
.setJsonModel(Model.class)
.setOnUpdateDetectedListener(new UpdateChecker.OnUpdateDetectedListener() {
@Override
public void onUpdateDetected(Object info)
{
try {
Model model = (Model) info;
String str_curVer = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
String str_newVer = model.version;
// Check if the current version is lower than the new update version
if(UpdateChecker.compareVersion(str_curVer, str_newVer))
{
String txt = String.format("Name: %s\nVersion: %s\nDownload: %s\nDescription: %s",
model.name,
model.version,
model.downloadUrl,
model.description.get(0)
);
AlertDialog dlg = new AlertDialog.Builder(MainActivity.this).create();
dlg.setCancelable(true);
dlg.setCanceledOnTouchOutside(false);
dlg.setMessage(txt);
dlg.setTitle("Update Available");
dlg.show();
}
else
Toast.makeText(MainActivity.this, "You have the latest version!", Toast.LENGTH_LONG).show();
} catch(Exception e) {
e.printStackTrace();
}
}
});