Android Question Wait for intent to finish?

aidymp

Well-Known Member
Licensed User
Longtime User
Hi, I am installing an apk via:

B4X:
If tmp.EqualsIgnoreCase(".apk") Then
            Dim iIntent As Intent
            iIntent.Initialize(iIntent.ACTION_VIEW, "file://" & File.DirRootExternal&"/Download/"&filename)
            iIntent.SetType("application/vnd.android.package-archive")
            StartActivity(iIntent)
End If

Is there a way to know if the intent has finished? So I can for example delete the .apk??

Thanks

Aidy
 

aidymp

Well-Known Member
Licensed User
Longtime User
Yep! that works, just a note, there appears to be no documentation or examples of this anywhere unless im mistaken? But I did it, making a service module like so.

B4X:
#Region  Service Attributes
    #StartAtBoot: False
   
#End Region


Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim PE As PhoneEvents
    Dim PhoneId As PhoneId
 
End Sub
Sub Service_Create
     PE.InitializeWithPhoneState("PE",PhoneId)
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub PE_PackageRemoved (Package As String, Intent As Intent)
    Log("PackageRemoved: " & Package)
    Log(Intent.ExtrasToString)
End Sub
Sub PE_PackageAdded (Package As String, Intent As Intent)
    Log("PackageAdded: " & Package)
    Log(Intent.ExtrasToString)
    ' set the installed boolean in sub main to true. so it can be checked on activity resume.
    Main.installed=True

End Sub

Sub Service_Destroy

End Sub

Thanks

Aidy
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Sub PE_PackageAdded (Package As String, Intent As Intent)
Log("PackageAdded: " & Package)
Log(Intent.ExtrasToString)
' set the installed boolean in sub main to true. so it can be checked on activity resume.
Main.installed=True

End Sub
so you will set installed to true. NO MATTER WHICH PACKAGE has been installed???????????
 
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
so you will set installed to true. NO MATTER WHICH PACKAGE has been installed???????????

To be honest, i think the chances of someone installing something else at the same time as my appstore type app does is very slim. but out of interest, how can i find the package name from the file prior to installing it?

Thanks

Aidy
 
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
I don't think that there is a simple way to do it. You can unzip the APK and parse the compiled manifest file (it is not a text file anymore at that point).

Thanks, that is why i settled for my solution...

Aidy
 
Upvote 0
Top