External Application Launch from another program

alvinmb

Member
Licensed User
Longtime User
How would you go about launching an external application from a button in a Basic4android application, and return to your B4a app when you close the app that you just launched?
 

Kevin

Well-Known Member
Licensed User
Longtime User
Replace com.package.tolaunch with the package name of the app you want to launch. If the user exits (backs out of) the launched app, Android will automatically return to your app afterwards.


B4X:
Sub YourButton_Click
  Try
    Dim Intent1 As Intent
    Dim pm as PackageManager
    Intent1 = pm.GetApplicationIntent ("com.package.tolaunch")
    StartActivity (Intent1)
      Catch
      ToastMessageShow ("Failed to launch app!  Is it installed?", True)
  End Try
End Sub
 
Upvote 0

AntAnt

Member
Licensed User
Longtime User
Hi there,
is the package enough to launch the application? I mean: don't you need to also specify apk file name?
Thanks in advance
A.
 
Upvote 0

AntAnt

Member
Licensed User
Longtime User
Eheh great! Thank you very much.
I tested it with my app and it works. Now, one (hopefully last) question.
I have to add some "string+relative command" to the intent.
With java/android would use Intent.putExtra (String name, String value)
Now I'm looking at b4a intent instance and it gives a method putExtra but it has these expected parameters:
Intent.putExtra(String name, Value Obj).
For instance, having to pass to the putExtra: "max_number"], 2
how is it suppose to do it, as it doesnt accept an int type as second parameter?
Thanks again
A.
 
Upvote 0

AntAnt

Member
Licensed User
Longtime User
ah of course the same issue with boolean types as second parameters (or strings..or any other type not object)
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
In B4A, the second parameter in PutExtra is an OBJECT, not a string
B4X:
myIntent.PutExtra(Name As String, Value As Object)
You could do something like:
B4X:
myIntent.PutExtra("max_number", "2")
 
Last edited:
Upvote 0

Juan Pedro Arce

Member
Licensed User
Longtime User
Ok, great, the answer shows the solution, but how can one get the name of the app in the Is there a way to obtain the name of the application in the form of "com.package.tolaunch" for a specific app? For example I am trying to call "MDScan Lite" (Document Scan into PDF). Is there a way to get the name in the package notation?
 
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
Hi friends,

just 2 questions:

1) is it possible to "click" on a button in the external app by Intent?
2) does
B4X:
Intent1.PutExtra("EditText_01", "XYZ")
putting the Text "XYZ" into the field?

Thank you for your help.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
1) NO
2) yes, if the receiving app supports such "extra". But usually NO
 
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
@DonManfred: Thank you for your response.

My problem is ... I have two own apps.
In the first app is a number generated. I want to click a button and open the other app. That works fine.

But then I want to click automatically into the other app to get onto a panel and then I want automatically copy the number from the first app into a TextEdit in the other app.

Is there any idea?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

JOTHA

Well-Known Member
Licensed User
Longtime User
Hello DonManfred,

thank you for the links above.
I've read the first one, but it was too much for the first time ... I searched for a "fast-and-easy-solution".

But now it seems that I have to read and learn with more time ...

Thanks!
 
Upvote 0
Top