JSON-based Update Checker
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' )
UpdateChecker checker = UpdateChecker .getInstance (context );
Set custom json model (example)
checker .setJsonModel (MyModel .class );
public class MyModel
{
@ SerializedName ("description" )
List <String > description ;
@ SerializedName ("name" )
String name ;
@ SerializedName ("version" )
String version ;
@ SerializedName ("downloadUrl" )
String downloadUrl ;
}
JSON File to read to (example)
{
"name" : " Test App" ,
"version" : " 1.2.0" ,
"description" : [" My description" , " Test description" ],
"downloadUrl" : " https://testurl.com/download"
}
checker .shouldAutoRun (true );
Enable update on both mobile networks
checker .shouldCheckUpdateOnWifiOnly (false );
checker .shouldAutoInstall (true );
Set the url of the json file
checker .setUpdateLogsUrl ("https://urlhere" );
//Returns the filepath of the downloaded app
UpdateChecker .downloadUpdate ("https://urlHere" , "filename.apk" );
Installing the app manually
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\n Version: %s\n Download: %s\n Description: %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 ();
}
}
});