javiersantos/AppUpdater

Issue with versionCode check from JSON

enwokoma opened this issue · 1 comments

  • I have verified there are no duplicate active or recent bugs, questions, or requests.
  • I have verified that I am using the latest version of AppUpdater.
  • I have given my issue a non-generic title.
  • I have read over the README, Wiki and FAQs (before asking questions on how to do something).
Details
  • PiracyChecker version: 2.x.x
  • Device OS version: 7.1.1
  • Device Manufacturer: LG
  • Device Name: Nexus 5X
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"
  ]
}
  1. 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.

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
}