Android Question Help about AppUpdating 2.0

universengo

Member
Hello everyone!
I use AppUpdating example and only change version name, the package name and link (with Dropbox link). See my code
B4X:
#Region  Project Attributes
    #ApplicationLabel: AppUpdating Example
    #VersionCode: 2
    #VersionName: 2.00
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

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.
    Private btnPackage As Button
    Private btnCurVer As Button
    Private btnWebVer As Button
    Private btnCompare As Button
    Private btnDwnld As Button
    Private btnInstall As Button
    Private ButtonUpdate As Button
    Private EditText1 As EditText
    Dim apkupdt As cl_appupdate
    Private phone As Phone
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    EditText1.Color=Colors.White
    EditText1.TextColor=Colors.Black
    EditText1.Text=$"Step by Step library usage${CRLF}"$
    If FirstTime Then
        apkupdt.Initialize(Me,"update")            'initializes the class
        apkupdt.Verbose = True                  'this one affects the verbosity of the logs
    End If 
      'ALWAYS NEEDED - this is your app's package name (see "Project/BuilConfigurations/Package")
      apkupdt.PackageName = "b4a.QLDL"
      'ALWAYS NEEDED - this is the complete path to the info text file holding the newer version number 
    'apkupdt.NewVerTxt = "http://www.dgconsulting.eu/free_apk/AppUpdateExample2.inf"
    apkupdt.NewVerTxt = "https://dl.dropbox.com/s/60g8lprpz8ydz06/QLDL.inf?dl=0"
      'ALWAYS NEEDED - this is the complete path to your newer apk
    'apkupdt.NewVerApk = "http://www.dgconsulting.eu/free_apk/AppUpdateExample2.apk"
    apkupdt.NewVerApk = "https://dl.dropbox.com/s/16nxxm0q61wrhby/QLDL.apk?dl=0"
    'OPTIONAL - Set credentials to access a protected folder. Not needed for this example
    apkupdt.setCredentials("test","test")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

'STEP 0: which is apk's package name?
'Can be called at any time not necessarily as step 0 as shown here
Sub btnPackage_Click
    'Show package name
    EditText1.Text=$"${EditText1.Text}Package name: ${apkupdt.PackageName}${CRLF}"$
End Sub

'STEP 1: which is apk's current version number?
'Can be called at any time not necessarily as step 1 as shown here
Sub btnCurVer_Click
    'Read version number of currently executing apk
    apkupdt.ReadCurVN  'send out command; async result in update_UpdateComplete
End Sub
  
'STEP 2: just curious about eventual availability of a newer apk version, so we simply check for it
'Can be called at any time not necessarily as step 2 as shown here
Sub btnWebVer_Click
    'Read version number as showed in txt file on webserver
    apkupdt.ReadWebVN  'send out command; async result in update_UpdateComplete
End Sub

'STEP 3: compares current version number to the one reported by the webserver
'Must follows steps 1 and 2. Assuming no errors in steps 1 and 2
Sub btnCompare_Click
    If apkupdt.CurVN < apkupdt.WebVN Then
        EditText1.Text=$"${EditText1.Text}Newer version available${CRLF}"$
      Else
        EditText1.Text=$"${EditText1.Text}No newer version available${CRLF}"$
    End If
End Sub

'STEP 4: let's download the apk published on the webserver. No check on its version; just download it
'Can be called at any time not necessarily as step 4 as shown here
Sub btnDwnld_Click
      'download apk from webserver raising appropriate errors when problems arise
    apkupdt.DownloadApk  'send out command; async result in update_UpdateComplete
End Sub

'STEP 5: let's ask the user to install an apk's newer version, previously downloaded
'Must follow step 4.
Sub btnInstall_Click
    Wait For (CheckInstallationRequirements) Complete (Result As Boolean)
    apkupdt.InstallApk(Result)  'send out command; async result in update_UpdateComplete
End Sub

'Do it all (steps 1 to 5) with a single call
Sub ButtonUpdate_Click
    EditText1.Text=$"A single sub call does it all${CRLF}"$
    Wait For (CheckInstallationRequirements) Complete (Result As Boolean)
      'OPTIONAL - if you like to show a splash screen while checking for a newer apk goes on
    apkupdt.SetAndStartSplashScreen(Activity,LoadBitmap(File.DirAssets, "updating.jpg"))
      'NEEDED - this is the one you need if you want to perform "automatic" updating of your apk
    apkupdt.UpdateApk(Result) 'checks for newer apk, downloads it and asks the user to install it                                                 
End Sub

'This subs gets called after each command is executed
Sub update_UpdateComplete
    LogColor($"UpdateComplete - time: ${DateTime.Time(DateTime.Now)}"$, 0xFF556B2F)
     apkupdt.StopSplashScreen
    'too lazy to manage error conditions..check apkupdt.ERR_xxx codes if you like
    Select apkupdt.Status
        Case apkupdt.OK_CURVER
            EditText1.Text=$"${EditText1.Text}Running apk version: ${apkupdt.CurVN}${CRLF}"$
        Case apkupdt.OK_WEBVER
            EditText1.Text=$"${EditText1.Text}Webserver apk version: ${apkupdt.WebVN}${CRLF}"$
            EditText1.Text=$"${EditText1.Text}Optional Change Log data: ${apkupdt.WebChangeLog}${CRLF}"$
            EditText1.Text=$"${EditText1.Text}Optional FileSize Log data: ${apkupdt.WebFileSize}${CRLF}"$
        Case apkupdt.OK_NEWERAPK
            EditText1.Text=$"${EditText1.Text}Newer version available${CRLF}"$
        Case apkupdt.NO_NEWERAPK
            EditText1.Text=$"${EditText1.Text}No newer version available${CRLF}"$
        Case apkupdt.OK_DOWNLOAD
            EditText1.Text=$"${EditText1.Text}Newer version downloaded${CRLF}"$
        Case apkupdt.OK_INSTALL
            EditText1.Text=$"${EditText1.Text}User asked to install newer version${CRLF}"$
        Case apkupdt.ERR_NOPERM
            Log("No permission to install")
            EditText1.Text=$"${EditText1.Text}User gave no permission to install${CRLF}"$
        Case Else
            EditText1.Text=$"${EditText1.Text}Status: ${apkupdt.Status}${CRLF}"$
    End Select
End Sub

#Region version-safe-apk-installation
'https://www.b4x.com/android/forum/threads/version-safe-apk-installation.87667/

'Check whether we already have permission for install other apps.
'If not we open the relevant settings page
'then wait for Activity_Resume and check the value of CanRequestPackageInstalls again
Private Sub CheckInstallationRequirements As ResumableSub
    If File.ExternalWritable = False Then
        MsgboxAsync("Storage card not available. Make sure that your device is not connected in USB storage mode.", "")
        Return False
    Else If phone.SdkVersion >= 26 And apkupdt.CanRequestPackageInstalls = False Then
        MsgboxAsync("Please allow me to install applications.", "")
        Wait For Msgbox_Result(Result As Int)
        Dim in As Intent
        in.Initialize("android.settings.MANAGE_UNKNOWN_APP_SOURCES", "package:" & Application.PackageName)
        StartActivity(in)
        Wait For Activity_Resume '<-- wait for Activity_Resume
        Return apkupdt.CanRequestPackageInstalls
    Else If apkupdt.CheckNonMarketAppsEnabled = False Then
        MsgboxAsync("Please enable installation of non-market applications." & CRLF & "Under Settings - Security - Unknown sources" _
             & CRLF & "Or Settings - Applications - Unknown sources", "")
        Return False
    Else
        Return True
    End If
End Sub
#End Region

I get my log :

with btnWebVer and btnDwnld button : sending message to waiting queue of uninitialized activity (submitjob)
and then No answer

Please help me to finish this error. Many thanks.
 

udg

Expert
Licensed User
Longtime User
Hi,
I never used AU withy dropbox but there a few threads about it in the Forum. Just search for "appupdate dropbox".
One of them is this one.

You can even use one of the more recent Dropbox libraries to download files and keep bits of AU to "orchestrate" the main logic.
 
Upvote 0

universengo

Member
Hi,
I never used AU withy dropbox but there a few threads about it in the Forum. Just search for "appupdate dropbox".
One of them is this one.

You can even use one of the more recent Dropbox libraries to download files and keep bits of AU to "orchestrate" the main logic.
Thank you udg.
I have just used as your link (AppUpdate 1.02 with Dropbox) but it was still not worked.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi,
you should in any case use AU 2.x because previous version is no more compatible with newer Android versions.
The link I suggested was just one among many that shows how to access a dropbox account and which states that operating that way it is usable with AU.
Unfortunately I never tried dropbox access myself. Eventually, try a more recent thread about AU + dropbox.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Unfortunately I never tried dropbox access myself. Eventually, try a more recent thread about AU + dropbox.
Dropbox is not something special.
The point is that one need to use FileProvider correctly when using AU on higher Androids.
It does´nt matter where the file is coming from.
Directdownload, Dropbox, Drive.....
 
Upvote 0

udg

Expert
Licensed User
Longtime User
You're right.
For what I recall from yesterday's search any existing AU+dropbox thread is old enough to not mention the FileProvider need. I could be wrong on this.
Anyway, as you say, it's just a matter to correctly access dropbox
 
Upvote 0

universengo

Member
Thank to udg and DonManfred!
I used AppUploading2.04 that was OK but one thing I didn't understand my log as below :
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
SDK#: 28 - UseFP: true - SharedFolder: /data/user/0/b4a.QLDL/files/shared
---- AppUpdating.UpdateApk
IsValidComplete start
before
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
after
Webserver's info file content:
��3��.��0��0��
    wrong row format in info file
    Current Version: 2.00
    -- TryApkUpdate
Donload ok? true
Copy2 (saving) ok? TRUE
    new apk version downloaded and ready to install
    user asked to install new apk
Update completed - Time: 14:20:58
** Activity (main) Pause, UserClosed = false **
As you see my file content is wrong (My link inf file: here)
What is a problem with my inf file?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Maybe the character set. Try with the attached one.
You have to change the extension fron "txt" to "inf", because upload rules don't allow to attach a "*.inf" file.
 

Attachments

  • QLDL.txt
    8 bytes · Views: 158
Last edited:
Upvote 0

universengo

Member
Maybe the character set. Try with the attached one.
You have to chenge the extension fron "txt" to "inf", because upload rules don't allow to attach a "*.inf" dile.
Thank you UDG!
I don't know your meaning as you say that change "txt"->"inf" but don't allow to attach a "*.inf" file ?
And my link is QLDL.inf that is ready a ".inf" file
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi,
I mean that Forum's rules don't allow an inf extension to file attached to posts. So you should change it yourself from txt to inf if you want to use the example file I provided above. Another possibility is to use Windows block-notes to write your inf file; it should use plain ASCII text as default.
 
Upvote 0

universengo

Member
Hi,
I mean that Forum's rules don't allow an inf extension to file attached to posts. So you should change it yourself from txt to inf if you want to use the example file I provided above. Another possibility is to use Windows block-notes to write your inf file; it should use plain ASCII text as default.
Thank you UDG so much! Let me try it and I will show you the result as soon as posible!
 
Upvote 0

universengo

Member
Hello everyone!
@udg and DonManfred
I need your hellp!

I still used this example as first post but now I would like to get information when I start my app.
So I put these these code into Sub Activity_Create:
apkupdt.ReadCurVN
apkupdt.ReadWebVN
If apkupdt.CurVN < apkupdt.WebVN Then
EditText1.Text=$"${EditText1.Text}Newer version available${CRLF}"$
Else
EditText1.Text=$"${EditText1.Text}No newer version available${CRLF}"$

End If

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    EditText1.Color=Colors.White
    EditText1.TextColor=Colors.Black
    EditText1.Text=$"Step by Step library usage${CRLF}"$
    If FirstTime Then
        apkupdt.Initialize(Me,"update")            'initializes the class
        apkupdt.Verbose = True                  'this one affects the verbosity of the logs
    End If   
      'ALWAYS NEEDED - this is your app's package name (see "Project/BuilConfigurations/Package")
      apkupdt.PackageName = "b4a.example.appupdate2"
      'ALWAYS NEEDED - this is the complete path to the info text file holding the newer version number   
    apkupdt.NewVerTxt = "http://www.dgconsulting.eu/free_apk/AppUpdateExample2.inf"
      'ALWAYS NEEDED - this is the complete path to your newer apk
    apkupdt.NewVerApk = "http://www.dgconsulting.eu/free_apk/AppUpdateExample2.apk"
    'OPTIONAL - Set credentials to access a protected folder. Not needed for this example
    apkupdt.setCredentials("test","test")

    apkupdt.ReadCurVN
    apkupdt.ReadWebVN
    If apkupdt.CurVN < apkupdt.WebVN Then
        EditText1.Text=$"${EditText1.Text}Newer version available${CRLF}"$
    Else
        EditText1.Text=$"${EditText1.Text}No newer version available${CRLF}"$
    End If
End Sub

I get my code:
---- AppUpdating.ReadWebVN
IsValidComplete start


How can I get for checking new version when my app start up?
Many thanks!
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi,
in my original demo each step is performed clicking a button while you list them consecutively in Activity_Create.
Looking at the cl_appupdate class code you could see that while ReadWebVN uses WaitFor to download and check remote info file, ReadCurVN doesn't.
While is advisable to keep Activity_Create as fast and short as possible, a simple solution could be to modify ReadCurVN in the same way ReadWebVN is (i.e. using WaitFor) and IsValidCV to become a ResumableSub like IsvalidWV.

ps: when posting is generally more useful to show the whole log (I mean, what appeared before and after those two lines you copied?)
 
Upvote 0

universengo

Member
Hi,
in my original demo each step is performed clicking a button while you list them consecutively in Activity_Create.
Looking at the cl_appupdate class code you could see that while ReadWebVN uses WaitFor to download and check remote info file, ReadCurVN doesn't.
While is advisable to keep Activity_Create as fast and short as possible, a simple solution could be to modify ReadCurVN in the same way ReadWebVN is (i.e. using WaitFor) and IsValidCV to become a ResumableSub like IsvalidWV.

ps: when posting is generally more useful to show the whole log (I mean, what appeared before and after those two lines you copied?)

Thank you very much UDG! Let me try your way about using WaitFor as ResumableSub
Let me Update error code:
B4X:
** Activity (main) Create, isFirst = true **
SDK#: 28 - UseFP: true - SharedFolder: /data/user/0/b4a.example.appupdate2/files/shared
---- AppUpdating.ReadCurVN
    Current Version: 2.04
---- AppUpdating.ReadWebVN
IsValidComplete start
before
Error occurred on line: 121 (cl_appupdate)
java.lang.NumberFormatException: empty String
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
    at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.lang.Double.parseDouble(Double.java:538)
    at anywheresoftware.b4a.debug.RDebugUtils.numberCast(RDebugUtils.java:58)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.appupdate2.main.afterFirstLayout(main.java:105)
    at b4a.example.appupdate2.main.access$000(main.java:17)
    at b4a.example.appupdate2.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7156)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

P/s: If you have a example code as my question. Please share me your links. Thanks!
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi,
the error shows that the remote info file is not configured as expected. You can activate the "verbose" option to see in logs a more complete message.
Anyway, pay attention to this caution note:
expected row format: ver=x.yz where "ver" could be any term and x.yz is the version number
'Attn: no spaces allowed between equal sign and version number
'Optionally that first line of text could be followed by ChangeLog and FileSize sections


That means that remote text file could be like:
B4X:
ver=3.54
<ChangeLog>
3.54 corrects some errors
3.00 new interface
</ChangeLog>
<FileSize>
1454000
</FileSize>

No need to modify class code as per post #15 above if the error is the one about the info file structure. It won't harm to consider the WaitFor as discussed, but it will not solve the error reported, IMHO.
 
Upvote 0

universengo

Member
Thanks udg!.
I think it is not error by my file because the file was uploaded by you as below:
B4X:
ver=2.11 <ChangeLog> ver 1.01 - initial release ver 1.87 - added status codes ver 2.11 - bug fixes </ChangeLog> <FileSize> 1042287 </FileSize>
I think that error at row compare CV with WV while WV is null (isnot valid).
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi @universengo ,
I attach here an export of version 2.03 of AU demo. On my PC I compiled it by B4A 10.0 then ran it.
It shows version 2.03 local and 2.11 remote. Then I go to the last step (install apk), the app closes itself and start again; this time it shows 2.11 as its local version.
So it seems to work as expected.

Please try it "as is" just to confirm that it works for you too. Then it could be modified in order to have a "silent check" on app startup (if this is your goal).
 

Attachments

  • AUDemo203.zip
    38.7 KB · Views: 172
Upvote 0

universengo

Member
Hi @universengo ,
I attach here an export of version 2.03 of AU demo. On my PC I compiled it by B4A 10.0 then ran it.
It shows version 2.03 local and 2.11 remote. Then I go to the last step (install apk), the app closes itself and start again; this time it shows 2.11 as its local version.
So it seems to work as expected.

Please try it "as is" just to confirm that it works for you too. Then it could be modified in order to have a "silent check" on app startup (if this is your goal).

Thank to UDG!
I think that I have solved this error
My way is put it in Sub update_UpdateComplete
That's perfect, see my code below :
B4X:
Sub update_UpdateComplete
    LogColor($"UpdateComplete - time: ${DateTime.Time(DateTime.Now)}"$, 0xFF556B2F)
     apkupdt.StopSplashScreen
    'too lazy to manage error conditions..check apkupdt.ERR_xxx codes if you like
    Select apkupdt.Status
        Case apkupdt.OK_CURVER
            EditText1.Text=$"${EditText1.Text}Running apk version: ${apkupdt.CurVN}${CRLF}"$
        Case apkupdt.OK_WEBVER
            EditText1.Text=$"${EditText1.Text}Webserver apk version: ${apkupdt.WebVN}${CRLF}"$
            EditText1.Text=$"${EditText1.Text}Optional Change Log data: ${apkupdt.WebChangeLog}${CRLF}"$
            EditText1.Text=$"${EditText1.Text}Optional FileSize Log data: ${apkupdt.WebFileSize}${CRLF}"$

' MY CODE UPDATE HERE----->
            Msgbox2Async($"Webserver apk version: ${apkupdt.WebVN} (${apkupdt.WebFileSize}) ! UPDATE ?"$, "New Infomation", "Update", "", "Cancel", Null, True)
            Wait For Msgbox_Result (ResultUpdate As Int)
            If ResultUpdate = DialogResponse.POSITIVE Then
                '====Update===
                Wait For (CheckInstallationRequirements) Complete (Result As Boolean)
                'OPTIONAL - if you like to show a splash screen while checking for a newer apk goes on
                'apkupdt.SetAndStartSplashScreen(Activity,LoadBitmap(File.DirAssets, "updating.jpg"))
                'NEEDED - this is the one you need if you want to perform "automatic" updating of your apk
                apkupdt.UpdateApk(Result) 'checks for newer apk, downloads it and asks the user to install it
            End If
'-----END CODE---->

        Case apkupdt.OK_NEWERAPK
            EditText1.Text=$"${EditText1.Text}Newer version available${CRLF}"$
        Case apkupdt.NO_NEWERAPK
            EditText1.Text=$"${EditText1.Text}No newer version available${CRLF}"$
        Case apkupdt.OK_DOWNLOAD
            EditText1.Text=$"${EditText1.Text}Newer version downloaded${CRLF}"$
        Case apkupdt.OK_INSTALL
            EditText1.Text=$"${EditText1.Text}User asked to install newer version${CRLF}"$
        Case apkupdt.ERR_NOPERM
            Log("No permission to install")
            EditText1.Text=$"${EditText1.Text}User gave no permission to install${CRLF}"$
        Case Else
            EditText1.Text=$"${EditText1.Text}Status: ${apkupdt.Status}${CRLF}"$
    End Select
End Sub
 
  • Like
Reactions: udg
Upvote 0
Top