Android Question CheckInstallationRequirements in a class

udg

Expert
Licensed User
Longtime User
Hi,
I'm using the code from this thread in a class embedded in a library.
When it comes to sub CheckInstallationRequirements we read Wait For Activity_Resume '<-- wait for Activity_Resume, as way to wait for a user decision.
Is it safe to use it in the context above? Should I read that activity as the one that initialized the class and later launched the new install request?

I tried "as is" and it works, but I prefer to ask before publishing a possibly failing lib.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm using the code from this thread in a class embedded in a library.
CheckInstallationRequirements is actually from this thread: Version safe APK installation

It is not safe the handle Activity_Resume event in the class code. You should handle it in the activity module and call a sub in your class. This means that the developer using your library will need to add this call.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
So, the developer should add three functions to his/her code: CheckInstallationRequirements, CanRequestPackageInstalls, CheckNonMarketAppsEnabled
Then, when it's time to install an already downloaded apk file, he/she uses:
B4X:
Wait For (CheckInstallationRequirements) Complete (Result As Boolean)
If Result Then
     <call a sub in my code that does the SendInstall making use of GetURI>
else
     <act on the circumstance where the user negated consent to install newer apk>
end if
Is it right?

A question strictly related to my first one: does your comment still apply if I make use of the CallBackModule object collected at class init? Something like
B4X:
Dim cb As Activity = Callback
wait for cb_resume
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
A question strictly related to my first one: does your comment still apply if I make use of the CallBackModule object collected at class init?
This will not work.

Is it right?
Cannot really say without diving into your code. The developer needs to add some code that will delegate the Activity_Resume event from the activity to the class instance.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Thank you @Erel, but I'm not sure to have properly understood it.
Please find attached the code a developer should use, as for my understanding so far.

The only place to really inspect is btnInstall_Click where, after a successful CheckInstallationRequirements, I call a sub in my class which in turn makes use of an identical copy of your SendInstallIntent (only difference is the apk file name) and terminates calling the common exit point to all the other class' functions in order to give feedback in Main's update_UpdateComplete.

Just for completeness, InstallApk could be
B4X:
SendInstallIntent
sStatusCode = OK_INSTALL
If sVerbose Then Log(TAB & "user asked to install new apk")
Finito ' this is the exit point

Note: btnUpdate_click should be entrirely retooled so for now don't care about it.
 

Attachments

  • AUEx176.zip
    31.9 KB · Views: 160
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Make sure to test it on Android 8+ device.

2. The only problematic point in the original code is this line from CheckInstallationRequirements:
B4X:
Wait For Activity_Resume '<-- wait for Activity_Resume
You cannot wait for Activity_Resume from your class. The developers should check the value of CanRequestPackageInstalls in Activity_Resume.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
The developers should check the value of CanRequestPackageInstalls in Activity_Resume.
Sorry, but this one seems to add confusion to me.
My code in post#5 is modelled on your InstallAPK where nothing is in Activity_Resume while all the action is started in Button1_Click
B4X:
Sub Button1_Click
   Wait For (CheckInstallationRequirements) Complete (Result As Boolean)
   If Result Then
       SendInstallIntent
   End If
End Sub
I basically did the same, using BtnInstall_Click
B4X:
Sub btnInstall_Click
   Wait For (CheckInstallationRequirements) Complete (Result As Boolean)
   If Result Then
       apkupdt.InstallApk  'send out command; async result in update_UpdateComplete
   Else
       Log("No permission to install")
   End If
End Sub
Only difference is that, once the check is ok you call directly SendInstallIntent while I have it buried in my class because I'd like to retun a status code in update_UpdateComplete. To serve entirely its scope, I should call apkupdt.InstallApk(Result) passing the result of the check, causing my class to return back the proper status code.

BTW, since there happen to be nothing dangerous in subs CanRequestPackageInstalls and CheckNonMarketAppsEnabled, these could be made part of the class as public subs called by code in CheckInstallationRequirements from Main. This way only the latter would be a requirement for the programmer to be included in his/her code.

If you still see problems with the above, could you kindly show some example code? I could even send you a preliminary copy of my lib (that will be published as source anyway) so you can have a look at it. Let me know.

TIA
 
Upvote 0

udg

Expert
Licensed User
Longtime User
In my example the Activity_Resume event is handled in CheckInstallationRequirements sub.
Absolutely and I do exactly the same (having moved your exact code for CheckInstallationRequirements in Main).

The scheme I'm asking your approval for is:
1. The developer sets the Manifest as you did in your InstallAPK example
2. The developer includes in its Main (or other activity) your exact code for CheckInstallationRequirements
3. The developer init my class and plays with its methods. When it comes to the installation step of a newer apk (for the running app) the developer in his/her code uses something like what I showed in post #7 for BtnInstall_Click. As you can see the Wait For CheckInstallationRequirements happens in Main.

Since BtnInstall.Click calls a function in my class which makes use of an exact copy of your SendInstallIntent, the final result (once the intent is executed) should be that the user could accept the install and a newer copy of the running app will be launched or deny it and the class will return to update_UpdateComplete which is in the same activity (generally Main) that started the install request.

Will the above work? Do you see any other critical point or error?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Great! In 24/48h I expect the updated class to be published.
Thank you very much.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…