Android Question Launch a Playstore App from B4A App [Resolved]

Roger Daley

Well-Known Member
Licensed User
Hi All,
I am trying to start two Apps (Not mine) from my App. The aim, start a "video recorder" and an "upload to Google drive" with a button push.
I have extracted the code I am trying as "stand alone code". I have tried the "Package Name" and the "Launcher Name", same result.
All it does is bring up the settings menu. Neither APP is started.

Obviously I am missing something, any hints gratefully accepted.

    #Region  Project Attributes
    #ApplicationLabel: RECORD
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #BridgeLogger: True

#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.
    Private timer1 As Timer
    Private myIntent1 As Intent
    Private myIntent2 As Intent
    Private jo As JavaObject
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.
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    If FirstTime Then
        timer1.Initialize("Timer1", 500)
        timer1.Enabled = True
    End If

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub StartCamera
    myIntent1.SetComponent("com.kimcy929.secretvideorecorder")      'From Package Does not work
    'myIntent1.SetComponent("com.kimcy929.secretvideorecorder.VideoRecorderActivity_1")  'From Launcher Does not work
'    app:Background Video Recorder
'    package:com.kimcy929.secretvideorecorder
'    Launcher:com.kimcy929.secretvideorecorder.VideoRecorderActivity_1
End Sub

Sub StartUpload
    myIntent2.SetComponent("com.icecoldapps.synchronizeultimate")  'From Package Does not work
    'myIntent2.SetComponent("com.icecoldapps.synchronizeultimate")  'From Launcher  Does not work
'    app:Synchronize Ultimate
'    package:com.icecoldapps.synchronizeultimate
'    Launcher:com.icecoldapps.synchronizeultimate.viewStart1
End Sub

Sub CloseActivities
    jo.RunMethod("finishAffinity", Null)
End Sub

Sub Timer1_Tick
    timer1.Enabled = False                ' Stop Timer
End Sub


Active Member
Licensed User
Try this to launch the app, I installed the app and works, maybe there is another option but this works for me with almost any app.
Sub Button2_Click
End Sub

#Region LaunchOtherApp
'Usage: Launch another app, inside of your app meaning that when you click on recent apps button
'will show your app name and not the other app that you are launching,
'or as external app meaning that when you press the recent apps button will show your app name and
'the app that you are launching.
'packageName as String = this is the package name of the app that you want to launch, could be the partial package name too.
'LaunchUsingAlternativeMode as boolean = True for Launch inside of your app, False as external.
Sub RunAppByPackage(packageName As String, LaunchUsingAlternativeMode As Boolean)
    Dim Pm As PackageManager
    Dim Inte As Intent
    Dim st As String = packageName
    If packageName.IndexOf("/")=-1 Then
        Dim Packages As List
        Packages = Pm.GetInstalledPackages
        For i = 0 To Packages.size - 1
            If st.ToLowerCase.Contains(packageName.ToLowerCase) = True Then
                If Not(Inte.IsInitialized) Or LaunchUsingAlternativeMode Then
                    Inte.Initialize(Inte.ACTION_MAIN, "")
                    Dim packageNamePlusActivityName As String = GetIntentActivityFromAPackage(st)
                    If packageNamePlusActivityName.Length>0 Then Inte.SetComponent(packageNamePlusActivityName)
                End If
                Exit '<---Will pick the first package on the list
            End If
        Inte.Initialize(Inte.ACTION_MAIN, "")
    End If
        If Inte.IsInitialized Then StartActivity(Inte)
        Log("failed launching "&st)
    End Try
End Sub

'Usage : Return the first activity that found with the package name
Sub GetIntentActivityFromAPackage(packageName As String) As String
    Dim i As Int =0
    Dim pm As PackageManager
    Dim FoundFirstActivityName As String = ""
    Dim Intent1 As Intent =pm.GetApplicationIntent(packageName)
    For Each cn As String In pm.QueryIntentActivities(Intent1)
        If i=1 Then FoundFirstActivityName=cn
    Return FoundFirstActivityName
End Sub
#End Region LaunchOtherApp

Roger Daley

Well-Known Member
Licensed User

Thanks for the code it works well for launching either APP. Unfortunately when I use it to start both APPS they appear to clash and only one works. It depends on which order they are started.
I will keep trying.

Regards Roger