Hi, I would like to start Erels texteditor (see link) from my app as an intent, no send or receive needed (the feedback is via clipboard to get around file copy restrictions). As I am dumb on Java matters, can someone please help me how to call this intent properly? After terminating the texteditor, the calling app should resume. Erels text editor
The texteditor has to be compiled into an app with a package name. then start it by package name:
B4X:
Dim Intent1 As Intent
Intent1.Initialize("android.intent.action.MAIN", "")
Intent1.SetComponent("the.package.name/.MainActivity") ' Replace with the correct package and activity name
StartActivity(Intent1)
Thank you, the package name is clear to me, what's the "/ .Mainactivity"? The main activity of the texteditor (called program) or of the calling program?
Thank you, the package name is clear to me, what's the "/ .Mainactivity"? The main activity of the texteditor (called program) or of the calling program?
You can always find the intent with PackageManager.GetApplicationIntent - from the Phone library.
B4X:
Dim pm As PackageManager
StartActivity(pm.GetApplicationIntent("package.name.of.text.editor")
Or:
B4X:
Dim Intent1 As Intent
Intent1.Initialize("android.intent.action.MAIN", "")
Intent1.SetComponent("the.package.name/.main") ' Replace with the correct package. Activity name is always "main". Case sensitive.
StartActivity(Intent1)
Thanks to you both. Yes, I think I call with a bad package name so Android spawns the wrong app. I am out of house today but I will try asap and post a solution if tests are positive.
I copied the sample as presented when one right clicks on the GetApplicationIntent. Does not work. Throws this error:
java.lang.RuntimeException: Object should first be initialized (Intent).
B4X:
Dim in As Intent
Dim pm As PackageManager
in = pm.GetApplicationIntent("com.google.android.youtube")
If in.IsInitialized Then StartActivity(in)
StartActivity(in)
Some more strange info:
I listed the packages installed with
B4X:
Dim pm As PackageManager
Dim packages As List
packages = pm.GetInstalledPackages
For i = 0 To packages.Size - 1
Log(packages.Get(i))
Next
Appart from a b4a.example none of my B4a apps are listed, neither is Erels Texteditor. And they are not visible in the playstore as installed apps. b4a bridge is showing up though, but this is an app installed from playstore, and only those are listed. Android is 14.
Is there a trick to register apps compiled and run from B4a so they get recognized without installing them from playstore?
I copied the sample as presented when one right clicks on the GetApplicationIntent. Does not work. Throws this error:
java.lang.RuntimeException: Object should first be initialized (Intent).
B4X:
Dim in As Intent
Dim pm As PackageManager
in = pm.GetApplicationIntent("com.google.android.youtube")
If in.IsInitialized Then StartActivity(in)
StartActivity(in)
Indeed, thank you Teddy, the intent is now visible in the list, I can extract the proper name and it can be invoked.
There remains one question: Why does the calling app not resume when the intent app closes? In the method description it says it would resume. But maybe that is only for internal activities?