B4A Library AppUpdating 2.0 - update non-market apps

Time goes by, things change and old tools need to be updated.

AppUpdating 2.0 is a partial rewrite of AppUpdating, a lib written back in 2014 to allow the remote update of non-market applications hosted on a webserver.

Why AU 2.0? Main reason is Google's introduction of Android 8 and the profound changes on a few key points coming with it. But it was time to leverage B4x's new features too. And, finally, a bit of clean up is always due.. :)

On next two posts I'll describe the steps needed to make the lib work with your code.
Edit: see post#43 below for installing instructions related to version 2.05 and higher.

What the lib does is simply to check whether the version number reported by reading an info text file on your webserver is greater than the one showed in the running copy of your app. If it finds indication of a newer version, it downloads it, then it asks the user to install it.
Since we can't know if the user agrees to update the app, we simply go on with our app, knowing that a service burned in the lib will fire when the OS will signal that the user accepted to install the newly downloaded copy of the app. In this latter case, the same service will reload the app when ready.

Files attacched:
AppUpdating.b4xlib - version 2.05 packed following the new b4xlib standard
AU200_src - source code for the lib
AU200_demo - example program using the lib
AU200_lib - lib file compiled with B4A 8.30

Versions changelog
2.05 - made it compatible with simultaneous use of NB6
2.00 - initial release of AppUpdating 2.0
 

Attachments

  • AU200_demo.zip
    31.6 KB · Views: 1,487
  • AU200_src.zip
    14.9 KB · Views: 1,242
  • AU200_lib.zip
    25.3 KB · Views: 1,452
  • AppUpdating.b4xlib
    7.3 KB · Views: 983
Last edited:

udg

Expert
Licensed User
Longtime User
Thank you, @MbedAndroid
For an explanation why the original release isn't compatible with B4A, please read here.
I feel that is an important point that most developers need to be aware of.
 
Last edited:

MbedAndroid

Well-Known Member
Licensed User
Longtime User
there is a small question left on my side:
original UDG advised to insert the AddReceiverText(eu.dgconsulting.appupdating.newinst2,..... line into the manifest. After this modification into a b4xlib the compiler errors and i had to change this line into:
B4X:
AddReceiverText(newinst2,
  <intent-filter>
  <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    <data android:scheme="package" />
  </intent-filter>)

This compiles without a error, thus i think it should work, actually i'm not sure about this. Reading Erels topic about this https://www.b4x.com/android/forum/threads/service-gets-paused-when-app-is-updated.98933/#post-623210 the first parameter should be the service, thus the newinst2 service....
 

udg

Expert
Licensed User
Longtime User
Hi @MbedAndroid
I will look at it on next weekend, but as a first hint I'd look at the code of the newinst2 service where there's a reference to the broadcast intent that needs to be changed.
 

MbedAndroid

Well-Known Member
Licensed User
Longtime User
in the newinst2 code i found this:
B4X:
    If StartingIntent.Action = "android.intent.action.PACKAGE_REPLACED" Then
       If svcVerbose Then Log($"${TAB}Package REPLACED intent received!"$)
       pkg = GetPackageName
       If svcVerbose Then Log($"${TAB}package: ${pkg}"$)
       If StartingIntent.GetData = "package:" & pkg Then
           MyAppReload
       End If
   End If
i think as Erel adviced to change the PACKAGE_REPLACED into MY_PACKAGE_REPLACED , it should be also changed in the newinst2 code... "StartingIntent.Action = "android.intent.action.MY_PACKAGE_REPLACED""
 

udg

Expert
Licensed User
Longtime User
Absolutely. Another consideration is that MY_PACKAGE_REPLACED intent is sent only to that app and newinst2 is awaken only for it, so probabily a check is no more needed.
Previous version had the service newinst2 awaken each time any installed app was updated. So the check to understand whether tha broadcast was intented for this specific app.
 

MbedAndroid

Well-Known Member
Licensed User
Longtime User
i think the AddReceiverText(newinst2,..... line in the manifest is ok with the b4xlib but strangly i dont see any log in the newinst2 service_start when i update the app. The app simply closes and when you manually reload it, the new version is there....
 

alienhunter

Active Member
Licensed User
Longtime User
i think the AddReceiverText(newinst2,..... line in the manifest is ok with the b4xlib but strangly i dont see any log in the newinst2 service_start when i update the app. The app simply closes and when you manually reload it, the new version is there....

Hi
same here it does not open the new version only on older Devices
not even the log shows up looks like the service does not start
but it is updating

i renamed newinst2 to newinst

Update
after i found this on stackoverflow

B4X:
    <receiver
        android:name=".OnUpgradeBroadcastReceiver"
        android:enabled="@bool/is_at_most_api_11" >
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
            <data android:scheme="package" />
        </intent-filter>
    </receiver>
    <receiver
        android:name=".OnUpgradeBroadcastReceiver"
        android:enabled="@bool/is_at_least_api_12" >
        <intent-filter>
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
        </intent-filter>
    </receiver>


In the manifest

B4X:
AddReceiverText(newinst,
  <intent-filter>
  <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
>> this has to go   <data android:scheme="package" /> <<< for > api12
  </intent-filter>)


it is restarting the app with

B4X:
AddReceiverText(newinst,
  <intent-filter>
  <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
  </intent-filter>)

Capture.PNG

now the only thing is how to add this to the manifest
for old devices and new devices
i do not know this how

thanks AH
 
Last edited:

MbedAndroid

Well-Known Member
Licensed User
Longtime User
api12 is android 3?
Is the trick now renaming to newinst + the modification in the manifest?
As i tried already the modification as you showed.
Nb what tool you used for that screenshot?
 

alienhunter

Active Member
Licensed User
Longtime User
api12 is android 3?
Is the trick now renaming to newinst + the modification in the manifest?
As i tried already the modification as you showed.
Nb what tool you used for that screenshot?

It looks like the
<data android:scheme="package" /> has to be removed acroding to the post... it works on my phone samsung S9 with version 9
regardless to the newinst2 name
i use snipping tool (windows )
 

MbedAndroid

Well-Known Member
Licensed User
Longtime User
copy/past your lines into the manifest, but that didnt help
Still the app closes
can you attach your newinst file to have a check here?
 

alienhunter

Active Member
Licensed User
Longtime User
copy/past your lines into the manifest, but that didnt help
Still the app closes
can you attach your newinst file to have a check here?


sorry i forgot
since we do not have a Start intent "package"
this has to come out too

B4X:
Sub Service_Start (StartingIntent As Intent)
    LogColor("---- AppUpdating.newinst2: service_started", LogColor1)
    If svcVerbose Then
        Log($"${TAB}intent: ${StartingIntent}"$)
        Log($"${TAB}action: ${StartingIntent.Action}"$)
        Log($"${TAB}extra: ${StartingIntent.ExtrasToString}"$)
        Log($"${TAB}data: ${StartingIntent.GetData}"$)
    End If       
    If StartingIntent.Action = "android.intent.action.MY_PACKAGE_REPLACED" Then
        If svcVerbose Then Log($"${TAB}Package REPLACED intent received!"$)
        pkg = GetPackageName
        If svcVerbose Then Log($"${TAB}package: ${pkg}"$)
        'If StartingIntent.GetData = "package:" & pkg Then
            MyAppReload
        'End If
    End If   
End Sub
 

Attachments

  • newinst.bas
    1.6 KB · Views: 347

MbedAndroid

Well-Known Member
Licensed User
Longtime User
yeah.... thanks
newinst works!. The difference between your newinst and my newinst2 is this line
B4X:
    svcVerbose = False
UDG already told me some post ago : try set it to false.
 

potman100

Active Member
Licensed User
Longtime User
yeah.... thanks
newinst works!. The difference between your newinst and my newinst2 is this line
B4X:
    svcVerbose = False
UDG already told me some post ago : try set it to false.

Hi

Just tried this on Android 9, all works great till it installs and the it fails, Just Say : "App Not Installed".

Can't see any errors in the logs.

Any Ideas ?

Potman100
 

udg

Expert
Licensed User
Longtime User
Hi,
please try the solution showed here.

That should work since Tomas tried it both on Android 9 and Android 8 devices, uness there's something specific to your device and/or its configuration.
Anyway, test it as is and eventually post here about your results.
 

joe.dai

Member
sorry ,
when I test the app and press install is error
Where am I doing wrong ~~?

I only change the URL
thank you
2020-03-12_024439.jpg


2020-03-12_024004.jpg
 

udg

Expert
Licensed User
Longtime User
With some difficulty I can read a ClassNotFound error referring to "android.support$v4...".
I don't know if this is the case, but in other threads I've read this statement by Erel:
Whenever you see an error message with android.support.* you know that you are using an unjetified library. Run Tools - Jetifier. Make sure that the library is in the additional libraries folder.
 

jesuslizonsoluciones

Member
Licensed User
Longtime User
I am using version 2.0 of appupdating and when updating I get the following error

java.lang.ClassNotFoundException: android.support$v4$content$FileProvider

Can somebody help me
 

makis_best

Well-Known Member
Licensed User
Longtime User
Thanks @Erel

I change the library but now I get the error

B4X:
B4A Version: 10.60
Parsing code.    (1.10s)
    Java Version: 8
Building folders structure.    (0.43s)
Compiling code.    Error
Error parsing manifest script:
Module eu.dgconsulting.appupdating.newinst2_br not found (Manifest Editor)
 

MbedAndroid

Well-Known Member
Licensed User
Longtime User
the problem might be that your library hasnt newinst2 sub. Have a check in your manifest you got exactly this line
B4X:
AddReceiverText(newinst2,
  <intent-filter>
  <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
  </intent-filter>)
 
Top