Android Question Start Texteditor with intent

gezueb

Active Member
Licensed User
Longtime User
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
 

jkhazraji

Active Member
Licensed User
Longtime User
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)
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
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?
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
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?
of the texteditor
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
It does start a text editor, but with fotos. I have changed the package name to make sure it does not start the wrong one.
Calling code:
            Dim Intent1 As Intent
            Intent1.Initialize("android.intent.action.MAIN", "")
            Intent1.SetComponent("ch.andromedar.mytexteditor")
            StartActivity(Intent1)
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
It works now. I was confused about the /.MAIN, it seems to be the intent filter as noted in the manifest file and not the main activity of the app.
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
It works now. I was confused about the /.MAIN, it seems to be the intent filter as noted in the manifest file and not the main activity of the app.
Great. If it worked for you then it would work for the others. A click on the arrow above 0
1730224415506.png
will be appreciated, so that it is the solution.
Thanks
 
Upvote 1

gezueb

Active Member
Licensed User
Longtime User
Sad to say it does not yet work properly. I will come back when I have found out more.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
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)

Both not tested...
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
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.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
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)
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
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?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
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)
You need to add the permission to manifest
B4X:
AddManifestText(
<uses-permission
  android:name="android.permission.QUERY_ALL_PACKAGES"
  android:maxSdkVersion="34" />
)
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
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?
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
and where should i place acticity resume? After calling the intent
B4X:
            StartActivity(pm.GetApplicationIntent("ch.andromedar.mytexteditor"))
            Activity_Resume
this does not work
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
ok, short summary for others with similar problems:

I was asked to bring meals to seniors in near villages. So I decided to make an app that maintains an adress list and starts google navigation when a particular table row (adress) is selected. This part runs fine and the intent to spawn google maps runs as advertised.

But the adress list (table) must be maintained on a pc (display size) , be it with a B4J app or with a text editor. In my case, it is stored as csv file.
With a USB link, I copy the csv file to the phone (Samsung Flip 3) /DCIM/ directory. Other methods of transfer would probably work as well. So far so good.

Now how to import the data into the file.DirInternal of my app? Frankly, I am fed up with the everchanging Android restrictions to copy file from external to internal or vice versa. Most examples in the forum that did run once do not anymore on later SDK's. So I decided to use the clipboard to import data into my app. This also runs fine.

On import click in my app, I now tried to spawn Erels Text Editor (enhanced with a copy to clipboard button) to select the proper csv file which will then be visible in the editor. The intent to start the text editor progammatically did not work. I found out that our lowly b4a apps are not listed in the "installed apps" (see post #15), only the stuff that is part of the system or downloaded from playstore is listed. And what's not listed cannot be started with an intent, regardless of the method used!

Now Teddybears contribution is vital:
B4X:
AddManifestText(
<uses-permission
  android:name="android.permission.QUERY_ALL_PACKAGES"
  android:maxSdkVersion="34" />
)
Without this permission it is simply not possible (anymore?) to intent an app that is not part of the system or installed from playstore, which is true of course for all our b4a apps not ported to the playstore.
So far so good, my problem is solved with the exception that my app does not resume when the texteditor is closed. I can live with that.
Anyway thanks to all of you for your kind advice!
 
Upvote 0
Top