Check app version

JonPM

Well-Known Member
Licensed User
Longtime User
Is it possible to check the installed app's version number without manually updating it (i.e. via MAP, etc)? I realize this is easy to do using a MAP file, but since the information is already embedded somewhere (since we enter it under Project>Application Version) it would be nice just to access it without saving it to persistent data.
 

jimmyjace

Member
Licensed User
Longtime User
Check app version on Google Play

Hi all,

I have used the code below to extract the app version on the local device, but how would I check this against the Google Play application and then show a popup to force an update?

Kind Regards,

Jason
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code parses Google Play html and searches for the version:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   SendVersionRequest("anywheresoftware.b4a.b4abridge")
End Sub
Sub SendVersionRequest(packagename As String)
   Dim j As HttpJob
   j.Initialize("version", Me)
   j.Download2("https://play.google.com/store/apps/details", Array As String("id", packagename))
End Sub
Sub VersionComplete(s As String)
   Dim m As Matcher
   m = Regex.Matcher("softwareVersion\" & QUOTE & ">([^<]+)</dd>", s)
   If m.Find Then
      Log("version = " & m.Group(1)) 'VERSION FOUND
   Else
      Log("version not found")
   End If
End Sub
Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "version" Then
         VersionComplete(Job.GetString)
      End If
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub

Requires HttpUtils2 modules.
 
Upvote 0

jimmyjace

Member
Licensed User
Longtime User
Erel,

Thanks for your reply on this, the code looks very straightforward and easy to implement.

Cheers,

Jason
 
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
When i open the app Deezer, he ask me for accept uptade

After there is choose between internet or playstore

playstore.jpg


How it's possible too open the link with Internet or playstore ?
 
Last edited:
Upvote 0

tufanv

Expert
Licensed User
Longtime User
is this code still works ? am trying it with a beta apk , coneection gives not found error ? ( maybe is it because a beta apk ? )
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
When I try this code I have one problem.

Sometimes it takes a while to come complete and if I am in a different Activity it flips me back into the Main Activity (where I did the call from)

This could be confusing to a user. Do I need to do this in a Service to stop it from doing this?

BobVal
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I actually have this in my Starter Service
B4X:
Sub Process_Globals
     '------------------------------------------------------------------------------
     '  Download the current version number from Google and see if same as us
     '------------------------------------------------------------------------------   
      Private  gHttpVersionJob                           As HttpJob
      Public    gGoogleStoreListingAddress         As String  = "https://play.google.com/store/apps/details?id=com.BOBs.BBS"
end sub

Public  Sub Service_Create
          gHttpVersionJob.Initialize("version_check", Me)
          gHttpVersionJob.Download(gGoogleStoreListingAddress)
end sub

B4X:
Public  Sub JobDone (Job As HttpJob)
         If  Job.JobName = "version_check" Then     
             If  Job.Success Then
                 Dim m As Matcher = Regex.Matcher("softwareVersion\" & QUOTE & ">([^<]+)</div>", Job.GetString)   
   
                If  m.Find Then             
                   Dim CurrentVersion   As String = m.Group(1)

             CurrentVersion  = CurrentVersion.Trim
         
#if Debug
             Log("Version[" &gVersionName &"]  CurrentVersion[" &CurrentVersion &"]")
#end if         
         
             gDifferentVersion        = CurrentVersion             
             gDifferentVersionAvailable = Not(gVersionName.EqualsIgnoreCase(CurrentVersion))
             
'             gNewVersionAvailable = Not(gVersionName.EqualsIgnoreCase(CurrentVersion))
'             
'             ToastMessageShow("NewerVersion:" &gNewVersion &"  -  " &gNewVersionAvailable, True)
             
           End If                 
         End If           
       end if
end sub

BobVal
 
Upvote 0

Schakalaka

Active Member
Licensed User
Longtime User
This code parses Google Play html and searches for the version:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   SendVersionRequest("anywheresoftware.b4a.b4abridge")
End Sub
Sub SendVersionRequest(packagename As String)
   Dim j As HttpJob
   j.Initialize("version", Me)
   j.Download2("https://play.google.com/store/apps/details", Array As String("id", packagename))
End Sub
Sub VersionComplete(s As String)
   Dim m As Matcher
   m = Regex.Matcher("softwareVersion\" & QUOTE & ">([^<]+)</dd>", s)
   If m.Find Then
      Log("version = " & m.Group(1)) 'VERSION FOUND
   Else
      Log("version not found")
   End If
End Sub
Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "version" Then
         VersionComplete(Job.GetString)
      End If
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub

Requires HttpUtils2 modules.

i'm sorry, but there alre lost some "DIM"..
and it don' t work as it is..
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I currently search the PS page for "Current Version" and if I find it then search after it for my APPs lead in.

All my Apps have a name lead-in ("B*Bs") in this case
B4X:
    #VersionName     : B*Bs-v3.07

On the Google PS this appears as:
upload_2018-8-19_14-47-58.png


So it this case I can search after "Current Version" for my app lead in "B*Bs" &"-v" and then know that is the start of my real version number.

Example:
I am sure that the below code could be done in a line of Regex but I am just not good at it.

B4X:
                   Dim Data       As String    = Job.GetString
                   Dim IndexToCV    As Int        = Data.IndexOf(">Current Version<")   ' Find Current Version in PS Page
                   
                   If  IndexToCV <> -1 Then
                       Data = Data.SubString(IndexToCV)
                       
                       Dim IndexToBBS As Int = Data.IndexOf("B*Bs-v")                       '  Find Lead In to my Apps Version Number
                       
                       If  IndexToBBS <> -1 Then                                   
                           Data = Data.SubString(IndexToBBS)
                           
                           Dim IndexToEnd As Int = Data.IndexOf("<")                           '  The < is end of data.
                           
                           If  IndexToEnd <> -1 Then
                               Dim CurrentVersion   As String = Data.SubString2(0, IndexToEnd)

                               CurrentVersion              = CurrentVersion.Trim
               
                               gDifferentVersion          = CurrentVersion                       
                               gDifferentVersionAvailable = Not(gVersionName.EqualsIgnoreCase(CurrentVersion))                               
                           End If
                       End If
                   End If

This is how I have been getting passed the always changing PS

Maybe this will help someone

BobVal
 
Upvote 0
Top