Android Question How can i tell the user that is using an older version of the app

Makumbi

Well-Known Member
Licensed User
Good morning members i normally makes changes in my app and i find that those changes have not be effected on other phones users how can i programmatically tell the user about the version they are using and the one updated thanks
 

Syd Wright

Well-Known Member
Licensed User
There is a simple solution: Just open the webpage of your app in the Playstore, e.g. one of my apps is: https://play.google.com/store/apps/details?id=brainznl2.dsh
and then use httpjob to download and read the source of this webpage and then "scrape" it.
There are two places where the version number is located: between <span class="htlgb"> and </span> and also after </script><script nonce= (between the square brackets)
Just compare this string to the actual version number in your code and then warn the user if it is not the same.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Google has changed the layout a few times in the past.

I suggest to get rid of the problem by yourself.

When uploading a app to the playstore you can upload a small textfile with all relevant info to your webserver too.

Download the textfile using okhttputils when the app starts and compare if the app is uptodate or not.
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Google has changed the layout a few times in the past.

I suggest to get rid of the problem by yourself.

When uploading a app to the playstore you can upload a small textfile with all relevant info to your webserver too.

Download the textfile using okhttputils when the app starts and compare if the app is uptodate or not.

Do you have any example on this platform. Do you mean something like this
B4X:
Sub GetLine(idx As Int) As String
    Dim text As List = File.ReadList(File.DirAssets,"VersionNumber.txt")
    If text.IsInitialized And text.Size>=idx-1 Then
        Return text.Get(idx-1)
    End If
    Return ""
End Sub

B4X:
    version = Application.VersionCode
'Log(GetLine(1))
If GetLine(1)=version Then
    Else
MsgboxAsync("You are Currently using An Old version of the App please Unstall and install the Latest Version Thanks","App Old Version")
        
            
End If
Please Don i have come up with something like this please guide me is it the right thing to do. 2. Does that mean that every time iam uploading a new app on the play store i have to update my version number Text file so that they match. 3. is there a code that i call use to automatically write the currently version number in the text file when iam releasing the version for use. because there is a possiblility of forgettting to update the version number text file thanks
 
Last edited:
Upvote 0

Syd Wright

Well-Known Member
Licensed User
To get the version number:
B4X:
Dim PM As PackageManager 'Part of the Phone library; Add this to Globals

Dim Version1 as string
Version1 = PM.GetVersionCode(GetPackageName)

Sub GetPackageName As String
    Dim r As Reflector
    Return r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
End Sub
and then do what I suggested. Don's idea will also work, but in that case you need a Server on your website and also you probably will forget to upload the small file with the new version some time in future (I know I would tend to forget it).
 
Last edited:
Upvote 0

Makumbi

Well-Known Member
Licensed User
B4X:
log(Application.Version Code)
is this one ok because from your explanation this is what i have managed to come up with

B4X:
Sub GetLine(idx As Int) As String
    Dim text As List = File.ReadList(File.DirAssets,"VersionNumber.txt")
    If text.IsInitialized And text.Size>=idx-1 Then
        Return text.Get(idx-1)
    End If
    Return ""
End Sub
dim version as String
    version = Application.VersionCode
'Log(GetLine(1))
If GetLine(1)=version Then
    Else
MsgboxAsync("You are Currently using An Old version of the App please Unstall and install the Latest Version Thanks","App Old Version")
        
            
End If
 
Upvote 0

Syd Wright

Well-Known Member
Licensed User
Here is a complete working code:
B4X:
'Activity module
Sub Process_Globals    'These global variables will be declared once when the application starts.    'These variables can be accessed from all modules.
End Sub

Sub Globals    'These global variables will be redeclared each time the activity is created.    'These variables can only be accessed from this module.   
    Dim PM As PackageManager
    Dim SourceText1 As String
    Dim Version1 As String
    Dim Version2 As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim j As HttpJob
    Dim n, m As Long
    Dim Date1 As String 
    
    j.Initialize("", Me)
    j.Download("https://play.google.com/store/apps/details?id=brainznl2.dsh")        'Change this to your own APK name

    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
      SourceText1=j.GetString
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",0) + 20
      n = SourceText1.IndexOf2("<div class="  & Chr(34) & "IQ1z0d",n) + 18
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      m = SourceText1.IndexOf2("</span>",n)
      If m>n Then Date1 = SourceText1.SubString2(n,m)
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      m = SourceText1.IndexOf2("</span>",n)
      Version1 = PM.GetVersionCode(GetPackageName)
      If m>n Then Version2 = SourceText1.SubString2(n,m)
      If Version1<>Version2 Then Msgbox("Current version is: " & Version1 & CRLF & "Playstore version is: " & Version2 & CRLF & "Uploaded: " & Date1,"Your App version is out of date")
    Else
      Log("Error")
    End If
    j.Release
End Sub

Sub GetPackageName As String
    Dim r As Reflector
    Return r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
I tested it on 3 of my apps in the Playstore. However, there is a risk that Google will frequently change the layout of this Playstore webpage.
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Here is a complete working code:
B4X:
'Activity module
Sub Process_Globals    'These global variables will be declared once when the application starts.    'These variables can be accessed from all modules.
End Sub

Sub Globals    'These global variables will be redeclared each time the activity is created.    'These variables can only be accessed from this module. 
    Dim PM As PackageManager
    Dim SourceText1 As String
    Dim Version1 As String
    Dim Version2 As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim j As HttpJob
    Dim n, m As Long
    Dim Date1 As String
  
    j.Initialize("", Me)
    j.Download("https://play.google.com/store/apps/details?id=brainznl2.dsh")        'Change this to your own APK name

    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
      SourceText1=j.GetString
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",0) + 20
      n = SourceText1.IndexOf2("<div class="  & Chr(34) & "IQ1z0d",n) + 18
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      m = SourceText1.IndexOf2("</span>",n)
      If m>n Then Date1 = SourceText1.SubString2(n,m)
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      n = SourceText1.IndexOf2("<span class=" & Chr(34) & "htlgb" & Chr(34) & ">",n) + 20
      m = SourceText1.IndexOf2("</span>",n)
      Version1 = PM.GetVersionCode(GetPackageName)
      If m>n Then Version2 = SourceText1.SubString2(n,m)
      If Version1<>Version2 Then Msgbox("Current version is: " & Version1 & CRLF & "Playstore version is: " & Version2 & CRLF & "Uploaded: " & Date1,"Your App version is out of date")
    Else
      Log("Error")
    End If
    j.Release
End Sub

Sub GetPackageName As String
    Dim r As Reflector
    Return r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
I tested it on 3 of my apps in the Playstore. However, there is a risk that Google will frequently change the layout of this Playstore webpage.


Since you have said that google changes their layout can i do something like this ony my server. so that every time upload a new version i update my server to the latest version number

B4X:
Sub LoadCheckVersion (d As String) As ResumableSub
    Log(d)
   
    Dim jt As HttpJob
    jt.Initialize("", Me)
    jt.Download("http://kccug.com/KabojjaApp/HandlerVBCheckVersion.ashx")
    'jt.GetRequest.Timeout = 3000' 10 seconds
    Wait For (jt) JobDone(jt As HttpJob)
    If jt.Success Then ' if job is success (http status code 200)
        Dim RetVal As String
        RetVal = jt.GetString
        Log(RetVal)
        If jt.GetString = "[]" Then
            'MsgboxAsync("No Records to Upload Yet for: " & CustID ,"SMIS")
            Return "Empty"
        Else
            Dim jp As JSONParser
            jp.Initialize(jt.GetString)
            'Log(jp) ' will pr
            Log($"Token(${jp})"$)
            Dim quotdt As List = jp.NextArray
            For Each quotd As Map In quotdt
                Log("CurrentVersion: " & quotd.Get("CurrentVersion"))
                Log("ReleaseDate: " & quotd.Get("ReleaseDate"))
                       
           
            Next
       

            Return "Good"
            jt.Release
        End If
    End If
End Sub
 
Last edited:
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
There is a simple solution: Just open the webpage of your app in the Playstore, e.g. one of my apps is: https://play.google.com/store/apps/details?id=brainznl2.dsh
and then use httpjob to download and read the source of this webpage and then "scrape" it.
There are two places where the version number is located: between <span class="htlgb"> and </span> and also after </script><script nonce= (between the square brackets)
Just compare this string to the actual version number in your code and then warn the user if it is not the same.
Hi Syd,
I just check Play market page for my app and for some reason current version is missing https://play.google.com/store/apps/details?id=alex.HCMS.EVV -am I missing something?
 
Upvote 0

Syd Wright

Well-Known Member
Licensed User
Hi Syd,
I just check Play market page for my app and for some reason current version is missing https://play.google.com/store/apps/details?id=alex.HCMS.EVV -am I missing something?
I just tried your link to the Playstore. For some reason it does not show any version number, also not in any webbrowser. Therefore my code reports that your version is "2.0 and up", which in fact is the required minimum Android version (i.e. the next item on the playstore webpage). Are you sure you have entered a version number in your app under the "Module attributes" behind "#VersionName:" before you uploaded your app to the Playstore?? My guess is that you only entered a number after "#VersionCode:".
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
I just tried your link to the Playstore. For some reason it does not show any version number, also not in any webbrowser. Therefore my code reports that your version is "2.0 and up", which in fact is the required minimum Android version (i.e. the next item on the playstore webpage). Are you sure you have entered a version number in your app under the "Module attributes" behind "#VersionName:" before you uploaded your app to the Playstore?? My guess is that you only entered a number after "#VersionCode:".
That's what I have

screen.jpg
 
Upvote 0

Syd Wright

Well-Known Member
Licensed User
Did you check what I suggested in your B4A app? It should look someting like this:
B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: My Test App
    #VersionCode: 2
    #VersionName: 1.21
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Did you check what I suggested in your B4A app? It should look someting like this:
B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: My Test App
    #VersionCode: 2
    #VersionName: 1.21
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region
Thanks, version name was empty.
 
Upvote 0
Top