Android Question (Solved)How to let the standard intent chooser display my app?

opus

Active Member
Licensed User
Longtime User
Hi, I want to create the following:
Outside my app(app not running), I want to click on a specific file, based on its extension, the standard intent chooser would show my app ( possibly together with other apps). When selection my app, the file will be used as a "command line argument" for my app.

The second part is probably done with the ContentChooser, I'll look into that. But how to do the first part, is it even possible to do that to the system when installing?
 

opus

Active Member
Licensed User
Longtime User
One thing I didn't realize was that I should use the Manifest Editor to "AddActivityText".
I got that OK.
However, even after I entered the follwing posted lines to the Manifest Editor the click on a *.dat-File doesn't do anything.
B4X:
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:pathPattern=".*\\.dat"/>
</intent-filter>)
What am I missing?
So far I only want that my app is started (or is a possible slection to be started if more then one app is connected to a .dat file)
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
<data android:pathPattern=".*\\.dat"/>
Shouldn't it preferably be written
B4X:
<data android:pathPattern=".*dat" />
or
<data android:pathPattern=".\\*dat" />

Because '\' is used as an escape character when the string is read from XML (before it is parsed as a pattern), you will need to double-escape: For example, a literal '*' would be written as "\\*" and a literal '\' would be written as "\\\\". This is basically the same as what you would need to write if constructing the string in Java code.
http://developer.android.com/guide/topics/manifest/data-element.html
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
I got it working using:
B4X:
AddActivityText(Main,
<intent-filter>
<actionandroid:name="android.intent.action.VIEW"/>
<categoryandroid:name="android.intent.category.DEFAULT"/>
<categoryandroid:name="android.intent.category.BROWSABLE"/>
<dataandroid:scheme="file"/>
<dataandroid:mimeType="*/*"/>
<dataandroid:pathPattern=".*\\.dat"/>
<dataandroid:host="*"/>
</intent-filter>)
However, my main problem was probably that I did try to use a file saved "somewhere". In my test-case I used a path like "/storage/emulated/0/Android/data/myPackage.myAppName". I guess the last part, which contains a dot made the problem. I was getting no result. When using a different path(without any dot) it is working. I guess all your suggestions would have worked also.

Thanks for the help.
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
You should not use hardcoded paths, not all devices are the same.
Correct!
I was using that path just for testing. The reason for that exact path was: "Me lazy!". I saved that file using my app, and that path is just the app-path (or whatever it is called in android). I learned it the hard way!
What I want to do finally is:
Be able to save the state of my game (done)
Be able to send that state via *whatever* (NOT done)
Be able to load a state (done)
Be able to start the app by clicking on a saved state (the app is starting, the string holding the path is intercepted, all other will be done this weekend)

The last is true, only if my wife doesn't ........ But thats another story.

Thanks for the help.
 
Upvote 0
Top