0

In my application I want to check the version number from the server and when this versionName > myVersionName show a dialog.

verionName is from the server comes as "version": "1.0.0.1" , and myVersionName is like 1.0.0.2.

I want that when 1.0.0.1 > 1.0.0.2 show a dialog.

But this verionNames are Strings. how can I check this in String?

Please help me

PakitoV
  • 2,476
  • 25
  • 34
BoboGoooool
  • 79
  • 1
  • 1
  • 6
  • take a look here -> https://stackoverflow.com/questions/198431/how-do-you-compare-two-version-strings-in-java – Levi Moreira May 02 '18 at 11:48
  • `String.compareTo()` compares in lexicographical order which should work just fine with your version numbers. Note that it works with the current, simple version numbers, no guarantees it will work when versioning changes to like 10.0.0.1 or 1.0.0.1.1 – Ben May 02 '18 at 11:48
  • how can server `versionName` be smaller than the `app'sversionname` ? even if it is ...you have to update the server versionName ? just after the release ! – Santanu Sur May 02 '18 at 11:49
  • @Ben, can you send to me code my friend? because I am amateur and really need your help. please – BoboGoooool May 02 '18 at 11:50
  • @Ben, until you use `"1.0.01.3".compareTo("1.0.1.2")`. This will be a problem. (Strange notation but seen somewhere... can't remember where) – AxelH May 02 '18 at 11:52
  • 1
    @AxelH yep. It only works if the versions are lexicographically comparable. But if they are it's a fast solution. Definitely not something I would bet my code's well-being on. – Ben May 02 '18 at 11:54
  • https://stackoverflow.com/a/6702029/3395198 – IntelliJ Amiya May 02 '18 at 11:55
  • I agree @Ben, we could easily use a regex to sanitize this notation first and keep the Comparable usage. – AxelH May 02 '18 at 11:59
  • I did write [an answer](https://stackoverflow.com/a/50134567/4391450) with a quick class to use this logic. This should be quit efficient for most case. – AxelH May 02 '18 at 12:56

0 Answers0