javiersantos / AppUpdater

A library that checks for your apps' updates on Google Play, GitHub, Amazon, F-Droid or your own server. API 9+ required.
Apache License 2.0
1.98k stars 412 forks source link

Issue with versionCode check from JSON #151

Closed enwokoma closed 5 years ago

enwokoma commented 5 years ago
Details
Builder
appUpdaterUtils = new AppUpdaterUtils(this)
                .setUpdateFrom(UpdateFrom.JSON)
                .setUpdateJSON("https://gigabytedevelopersinc.com/apps/sonshub/update/update-changelog.json")
                .withListener(new AppUpdaterUtils.UpdateListener() {
                    @Override
                    public void onSuccess(Update update, Boolean isUpdateAvailable) {
                        Log.d("Latest Version", update.getLatestVersion());
                        Log.d("Latest Version Code", String.valueOf(update.getLatestVersionCode()));
                        Log.d("Release notes", update.getReleaseNotes());
                        Log.d("URL", String.valueOf(update.getUrlToDownload()));
                        Log.d("Is update available?", Boolean.toString(isUpdateAvailable));

                        // Shows a custom bottomSheet
                    }

                    @Override
                    public void onFailed(AppUpdaterError appUpdaterError) {
                        Log.d("AppUpdater Error", "Something went wrong");
                    }
                });
        appUpdaterUtils.start();
Reproduction Steps
  1. Use the AppUpdaterUtils
  2. Use the UpdateFrom.JSON
  3. Declare the link to the JSON file (https://my-site.com/update/update-changelog.json)
  4. This is how my JSON looks
    {
    "latestVersion": "1.1",
    "latestVersionCode": 2,
    "url": "https://my-site.com/update/app.apk",
    "releaseNotes": [
    "- First evolution",
    "- Second evolution",
    "- Bug fixes"
    ]
    }
  5. Installed app has versionName of 1.0 and versionCode of 1
Expected Result

The update notice bottomsheet should be shown only when the versionName and versionCode is higher from the versionName and versionCode of the installed apk

Actual Result

With the JSON above, I get the update notice. But, when I change the info in the JSON to match the same with the installed app. Something like:

{
  "latestVersion": "1.0",
  "latestVersionCode": 1,
  "url": "https://my-site.com/update/app.apk",
  "releaseNotes": [
    "- First evolution",
    "- Second evolution",
    "- Bug fixes"
  ]
}

I still get the Update Notice... Even when I have installed the updated version of the app (the latest), I still get the Update Notice every time. Irrespective of how I change the JSON versionName and versionCode, I still get the Update Notice Something is not correct with the check.

enwokoma commented 5 years ago

No need, I have fixed the problem... Issue was that, I needed to call an if statement to check if the JSON versionCode is higher than the versionCode of the installed app. So far, so good. It works

Here is the change I made in the onSuccess callback


if (update.getLatestVersionCode() > BuildConfig.VERSION_CODE) {
     // Show Update bottomSheet
} else {
    // No Update
    // TODO: Do something when no update
}