https://github.com/snoopycodex/jsonupdatecheckerandroid
A JSON-based Update Checker (Customize-able)
https://github.com/snoopycodex/jsonupdatecheckerandroid
Last synced: 6 months ago
JSON representation
A JSON-based Update Checker (Customize-able)
- Host: GitHub
- URL: https://github.com/snoopycodex/jsonupdatecheckerandroid
- Owner: SnoopyCodeX
- License: mit
- Created: 2020-04-23T12:25:01.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-14T04:37:01.000Z (over 2 years ago)
- Last Synced: 2025-03-17T06:11:44.969Z (11 months ago)
- Language: Java
- Size: 230 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOGS.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# JSON-based Update Checker
[](https://facebook.com/SnoopyCodeX)
[](https://github.com/SnoopyCodeX/jsonupdatecheckerandroid/releases)
[](https://github.com/SnoopyCodeX/jsonupdatecheckerandroid)
[](https://github.com/SnoopyCodeX/jsonupdatecheckerandroid)

[](https://depshield.github.io)
[](https://travis-ci.org/SnoopyCodeX/jsonupdatecheckerandroid)
- [x] Customizeable
- [x] Easy to implement
- [x] JSON-based checker
- [x] Can download app
- [x] Can auto install app
- [x] Automatically check for updates
- [x] Lightweight library
- [x] Uses Google's [Gson Library](https://github.com/google/gson) 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
```groovy
compile project(':cdph_updatechecker_lib')
```
### JAR File (Unstable)
- Add this jar file to your app's libs directory
- (Unstable) [UpdateChecker - v22.0.0](https://raw.githubusercontent.com/SnoopyCodeX/jsonupdatecheckerandroid/master/Jar/v22.0.0-UpdateChecker.jar)
---
# Usage
### Initialize UpdateChecker
```java
UpdateChecker checker = UpdateChecker.getInstance(context);
```
---
### Set custom json model (example)
```java
checker.setJsonModel(MyModel.class);
public class MyModel
{
@SerializedName("description")
List description;
@SerializedName("name")
String name;
@SerializedName("version")
String version;
@SerializedName("downloadUrl")
String downloadUrl;
}
```
---
### JSON File to read to (example)
```json
{
"name": "Test App",
"version": "1.2.0",
"description": ["My description", "Test description"],
"downloadUrl": "https://testurl.com/download"
}
```
---
### Enable auto update
```java
checker.shouldAutoRun(true);
```
---
### Enable update on both mobile networks
```java
checker.shouldCheckUpdateOnWifiOnly(false);
```
---
### Enable auto installation
```java
checker.shouldAutoInstall(true);
```
---
### Set the url of the json file
```java
checker.setUpdateLogsUrl("https://urlhere");
```
---
### Downloading the app
```java
//Returns the filepath of the downloaded app
UpdateChecker.downloadUpdate("https://urlHere", "filename.apk");
```
---
### Installing the app manually
```java
UpdateChecker.installApp(file);
```
----
### Add listener
```java
checker.setOnUpdateDetectedListener(new UpdateChecker.OnUpdateDetectedListener() {
@Override
public void onUpdateDetected(Object info)
{}
});
```
### Demo Usage
```java
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();
}
}
});
```