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 will be appreciated, so that it is the solution.
Thanks
 
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
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…