Skip to content

SnoopyCodeX/jsonupdatecheckerandroid

Repository files navigation

JSON-based Update Checker

Developed by SnoopyCodeX Github Release Github Star Github Fork License DepShield Badge Build Status

  • 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

Setup

Clone this repo

  • 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')

JAR File (Unstable)


Usage

Initialize UpdateChecker

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"
}

Enable auto update

checker.shouldAutoRun(true);

Enable update on both mobile networks

checker.shouldCheckUpdateOnWifiOnly(false);

Enable auto installation

checker.shouldAutoInstall(true);

Set the url of the json file

checker.setUpdateLogsUrl("https://urlhere");

Downloading the app

//Returns the filepath of the downloaded app
UpdateChecker.downloadUpdate("https://urlHere", "filename.apk");

Installing the app manually

UpdateChecker.installApp(file);

Add listener

checker.setOnUpdateDetectedListener(new UpdateChecker.OnUpdateDetectedListener() {
    @Override
    public void onUpdateDetected(Object info)
    {}
});

Demo Usage

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();
			}
		}
	});

About

A JSON-based Update Checker (Customize-able)

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages