calling external app

marcomilazzo

Member
Licensed User
Longtime User
How can i call on application within my code ?
ad example i have an app "shutdown" that closes the phone
How can i call and run this app?
ciao e grazie
 

AlpVir

Well-Known Member
Licensed User
Longtime User
The following sub does what you ask. You just pass it a parameter that you can extract from the list of all applications.

B4X:
Sub AvviaIntent (Parametro As String)
       Dim in As Intent
       Dim pm As PackageManager
   
       in = pm.GetApplicationIntent(Parametro)
       If in.IsInitialized Then 
      StartActivity(in)
   Else
      Msgbox ("Non è possibile avviare " & Programma & CRLF & "( " & Parametro & " )","ERRORE")
   End If
End Sub

It requires the library Reflection

This piece of code lists all user-installed applications.

B4X:
Lista.Initialize 
   '--- elenco tutte le app installate dall'utente
   Obj1.Target = Obj1.GetContext
   Obj1.Target = Obj1.RunMethod("getPackageManager")                         
   Obj1.Target = Obj1.RunMethod2("getInstalledPackages", 0, "java.lang.int") 
   size = Obj1.RunMethod("size")
   For i = 0 To size -1
       Obj2.Target = Obj1.RunMethod2("get", i, "java.lang.int")             
       name = Obj2.GetField("packageName")
       Obj3.Target = Obj2.GetField("applicationInfo")                      
       flags = Obj3.GetField("flags")   
       Lista.Add (name.trim)
   Next    
   Lista.Sort (True)
 
Upvote 0
Top