S
S
Sergey Karbivnichy2022-01-16 14:37:34
Java
Sergey Karbivnichy, 2022-01-16 14:37:34

How do you compare versions of your app?

I have an application. Instead of going to the forums and posting a link to the new version when updating the application, I want to make the application connect to my server and check for a new version. But I can not find something on the Internet, how to compare versions. I think this is because the Play Market is mainly engaged in this. My application is not for Play Market'a. So how to compare, for example - "1.0.1", "1.2.99", "2.0.10"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2022-01-16
@hottabxp

Searched wrong. Here is the correct request for google - java compare 2 version strings
For myself, I chose the Semver4j library (it also works in Android).
Examples:
implementation 'com.vdurmont:semver4j:3.1.0'
isGreaterThan returns true if the version is strictly greater than the other one.

Semver sem = new Semver("1.2.3");
sem.isGreaterThan("1.2.2"); // true
sem.isGreaterThan("1.2.4"); // false
sem.isGreaterThan("1.2.3"); // false

isLowerThan returns true if the version is strictly lower than the other one.
Semver sem = new Semver("1.2.3");
sem.isLowerThan("1.2.2"); // false
sem.isLowerThan("1.2.4"); // true
sem.isLowerThan("1.2.3"); // false

isEqualTo returns true if the versions are exactly the same.
Semver sem = new Semver("1.2.3+sha123456789");
sem.isEqualTo("1.2.3+sha123456789"); // true
sem.isEqualTo("1.2.3+shaABCDEFGHI"); // false

isEquivalentTo returns true if the versions are the same (does not take the build information into account).
Semver sem = new Semver("1.2.3+sha123456789");
sem.isEquivalentTo("1.2.3+sha123456789"); // true
sem.isEquivalentTo("1.2.3+shaABCDEFGHI"); // true

O
Oleg, 2022-01-16
@402d

public final class BuildConfig {
...
  public static final int VERSION_CODE = 152;
  public static final String VERSION_NAME = "5.52.0";
}

Compare in integers BuildConfig.VERSION_CODE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question