Start an application

Yeshua

Member
Licensed User
Longtime User
this code start an application, but how do i start skype, messenger play, and whatsapp?

. . . or open the list of applications installed on the device and then launch them from there.

B4X:
Sub Button1_Click
Try
Dim pm As PackageManager
Dim i As Intent
i = pm.GetApplicationIntent ("com.facebook.katana")
StartActivity (i)
Catch
ToastMessageShow ("Failed to launch app!  Is it installed?", True)
End Try
End Sub
:sign0148:
 

Mahares

Expert
Licensed User
Longtime User
Since it is sometimes hard to recognize the package name, I added the package label to NJDude's listview. See below:
I replaced this line:
B4X:
ListView1.AddSingleLine2(Packages.Get(I), Packages.Get(I))
with this line:
B4X:
ListView1.AddTwoLines2(Packages.Get(I),pm.GetApplicationLabel(Packages.Get(I)),Packages.Get(I))
 
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
i try that and runs ok, but how i can order this list,i try with
B4X:
Packages.Sort(True)
and don´t runs.
thank you
 
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
no error only don´t sort the list.this is the code
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("start")
   Packages.Initialize   
            Packages = pm.GetInstalledPackages
            Packages.Sort(True)         
            For I = 0 To Packages.Size - 1            
                ListView1.AddSingleLine2(pm.GetApplicationLabel(Packages.Get(I)),Packages.Get(I))
               ListView1.FastScrollEnabled = True      
            Next
End Sub
thnak you
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Only one question.

In the simple "RunApp_Sample" you can start a new application ok.

But when you close this new App, RunApp_Sample is closed too.

How I can avoid this?

I want return to RunApp_Sample after closed the nw App.

Thanks in advance
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
No, Activity.Finish never is called.

Here you have the code

B4X:
Sub Process_Globals

End Sub

Sub Globals

    Dim ListView1 As ListView
    Dim pm As PackageManager
    Dim Packages As List               
               
End Sub

Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("Main")
               
    Packages = pm.GetInstalledPackages
    Packages.Sort(True)
    For I = 0 To Packages.Size - 1
        ListView1.AddSingleLine2(Packages.Get(I), Packages.Get(I))
    Next

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause(UserClosed As Boolean)

End Sub

'##########################
'######## Controls ########
'##########################

Sub ListView1_ItemClick(Position As Int, Value As Object)
    Dim i As Intent   
    i = pm.GetApplicationIntent(Value)
     If i.IsInitialized Then
        StartActivity(i)   
    Else
       ToastMessageShow("Cannot run app", False)
    End If           
End Sub
 
Upvote 0
Top