Android Question [Solved]How to get result from StartActivity(Intent)

opus

Active Member
Licensed User
Longtime User
Hi,
I'm using the AppUdating library https://www.b4x.com/android/forum/threads/appupdating-automate-apps-updating-from-a-webserver.37783/
When the update is presented to the user, started by
B4X:
Dim i As Intent
  i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(File.DirDefaultExternal, "tmp.apk"))
  i.SetType("application/vnd.android.package-archive")
  StartActivity(i)
I would like to get a feedback if the user cancled the installation of the new .apk.
Searching the Forum I found "StartActivityForResult", however I don't get how to incooperate it in here.

Al I need is a feedback into the original app, since if the user confirms the installation, the original app wil be killed in the process of updating.
 

opus

Active Member
Licensed User
Longtime User
Thanks for the reply.
Using the Event "PackageAdded" will not solve problem, since this Event will only fire if the Installation was accepted. However, I'm looking just for the opposite.
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
Looks like I got in working, using a Boolean which is set only if the Status from the apkUpdate tells me the user was asked o install (Checked in _UpdateComplete Event).
This Boolean is checked in the activity routine.
I'll look into more details after the weekend (busy with realworld stuff!)
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
I got it solved:
In the Activity_Resume Event I use:
B4X:
  If (UpdateTried=True) Then  'this Global Boolean is set to True in the _UpdateComplete Event.
       Dim Check As Int
       Check=Msgbox2(  MyResources.getapplicationString("UpdateTried"),MyResources.getapplicationString("UpdateTriedTitle"), MyResources.getapplicationString("UpdateTriedButtonFollowingUpdates"),"",MyResources.getapplicationString("UpdateTriedButtonCancelUpdates"),Null)
       If (Check=DialogResponse.negative)Then
         AutoUpdate=0 'Global Var holding the Setting for AutoUpdate
         StateManager.SetSetting("AutoUpdate",AutoUpdate)
         chbxAutoUpdate.Checked=False 'The OptionsView in which the AutoUpdate Setting can be set manualy
         StateManager.SaveSettings
       End If
       UpdateTried=False 'Reset the Boolean for further use.
   End If
and in the _UpdateComplete Event:
B4X:
Sub Updater_UpdateComplete
   Select apkupdt.Status
     Case apkupdt.OK_CURVER
       Log("Running apk version: " & apkupdt.CurVN)
     Case apkupdt.OK_WEBVER
       Log("Webserver apk version: " & apkupdt.WebVN)
       Log("Optional Change Log data: " & apkupdt.WebChangeLog)
     Case apkupdt.OK_NEWERAPK
       Log("Newer version available")
     Case apkupdt.NO_NEWERAPK
       Log("No newer version available")
     Case apkupdt.OK_DOWNLOAD
       Log("Newer version downloaded")
     Case apkupdt.OK_INSTALL
       Log("User asked to install newer version")
       UpdateTried=True
     Case Else
      Log("Status: "&apkupdt.Status)
   End Select
End Sub
 
Upvote 0
Top