Android Question Intent Explicit - Launch an app and pass it a file

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings, all.

How do I launch an app and pass it a file name? For example, I would like to pass file "1.txt" to Kingston Office so that the user can edit it.

This code launches Kingston Office:

B4X:
Try
Dim In As Intent
Dim app As Object
app="cn.wps.moffice_eng"
Dim pm As PackageManager
In = pm.GetApplicationIntent(app)
StartActivity(In)
Catch
  ToastMessageShow("error starting application.", True)
  Log(LastException)
End Try

How do I modify the intent to add the file "1.txt"?

I am truly a novice when it comes to Intents. Any and all help will be welcomed.

Thank you.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Erel.

In File Explorer (ES or other), when I touch a file like "1.txt", it gives me options as to which application can handle the file. When I choose one the options, Kingston Office or any other text editor, how does ES File Explorer know the intent to use when it launches the app and passes it a file?

Best regards.

Sandy
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Those are two different things, you can use an intent to show all the apps able to handle the file, but to SEND a file to a specific app like Erel said, you need to read the app's documentation.

This code for example will show all the available apps able to handle Text files.
B4X:
Dim i As Intent

i.Initialize(i.ACTION_VIEW, "")
i.SetType("text/plain")

StartActivity(i)
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Those are two different things, you can use an intent to show all the apps able to handle the file, but to SEND a file to a specific app like Erel said, you need to read the app's documentation.

This code for example will show all the available apps able to handle Text files.
B4X:
Dim i As Intent

i.Initialize(i.ACTION_VIEW, "")
i.SetType("text/plain")

StartActivity(i)

Thank you, NJ.

I understand what you are saying.

I am looking for an Explicit Intent, i.e., launch WPS with file 1.txt.

And the question that I have is the same:

In File Explorer (ES or other), when I touch a file like "1.txt", it gives me options as to which application can handle the file. When I choose one the options, Kingston Office or any other text editor, how does ES File Explorer know the intent to use when it launches the app and passes it a file?

I do appreciate your responses, time, and knowledge.

Best regards.

Sandy
 
Upvote 0

Jausa

Member
Licensed User
Longtime User
I have a similar question.
AdobeReader is the most used PDF reader.
I have an app which generates a .PDF Document
But i don't know how to open it.
:(
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Assuming you have a PDF file named "test.pdf" saved on DirDefaultExternal:
B4X:
Dim i As Intent

i.Initialize(i.ACTION_VIEW, "file:///" & File.DirDefaultExternal & "/test.pdf")
i.SetComponent("com.adobe.reader/.AdobeReader")

StartActivity(i)

Thanks for this, NJ. This worked for me as I learn more about intents.

How did you determine AdobeReader in i.SetComponent("com.adobe.reader/.AdobeReader")? As opposed to "Adobe Reader" as it shows in Apps.
How did you determine ACTION_VIEW was a valid parameter for Adobe Reader?

Thanks again.

Sandy
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
ACTION_VIEW is used to open and view files, and the activity (AdobeReader) is the one that handles that, the developer documents that, or, you could also look the activities inside the app and try to find the right one.
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Thanks again for your valuable time, NJ.

How can you look at the activities inside an app?

Sandy
Novice at Intents
Zero at JAVA
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Thanks again for your valuable time, NJ.

How can you look at the activities inside an app?

Sandy
Novice at Intents
Zero at JAVA

Thank you, NJ.

I will take a look at it. Have an appointment now.

Best regards.

Sandy
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
You can try this "amazing" app: Phone Info written by yours truly :D

All humility aside, I did download the amazing app on one of my tablets and it is well - amazing. I gave it a 5 star rating.

NOTE:
To find your Phone Info app in Google Play from Android, I had to search for "Phone Info Uncle". On "Phone Info" search - 6 other apps came up, but not yours
Why restrict it to phones?

Please see next Post..
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
I still have a mental block related to my original question:

In File Explorer (ES or other), when I touch a file like "1.txt", it gives me options as to which application can handle the file. When I choose one the options, Kingston Office, how does ES File Explorer know the intent to use when it launches the app and passes the app the file selected by the user?

It would make sense to me that ES File Explorer has a general intent to launch an app and pass it a file name. The apps themselves must adhere to this standard... But I will repeat it: Novice at Intents and Zero at JAVA... Or maybe, I am a bit stuck in MS Windows: "In the Run dialog box, type the full path for the Winword.exe file (including the file name), ..."

Would appreciate any and all help.

Sandy
 
Upvote 0
Top