We have developed an Android app which is used for rendering files of our custom file type (.vds). I am able to launch my app for all the files (.vds file) which are stored on local storage, but if the files is stored on Box and I try to access them using the Box Android App then I am facing issues. I have created the following intent filter:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.vds" />
The problem is that in the corresponding activity I am able to get the intent, but if I try to read the URI (as our rendering logic is based upon file location) it gives me a path which doesn't exists on the SD card. What happens if we try to open a file using Box Android Native App? Where is the file downloaded and how should the downloaded file be accessed?
This may solve ur problem. Add the bellow intent filter.
<activity android:name=".Activity"
android:screenOrientation="portrait"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.EDIT"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:pathPattern="*.snowdragon"/>
<data android:mimeType="text/snowdragon"/>
</intent-filter>
</activity>
As noted above I've run into the same problem. While I've not found what I would consider to be The Right Solution(TM) I do have a couple of things to add that might be useful to others:
First, I've discovered that if I download the file in Box (not the same as mark for offline) then clicking the item in either the download result dialog or in the subsequent notification that appears at the bottom of the app works. Once you've dismissed that notification however, there does not seem to be a way to get back to the downloaded file from within Box.
Second, and let me qualify this by saying that I've not looked very closely at it yet but I think one could use the filename info in the intents for non-existent files to retrieve the file via the Box API, either directly from the cloud or possibly via API call to retrieve offline items. I'm wondering if this is actually what Box is trying to get us to do with these bogus file paths, considering that they are so blatantly bogus:
12-04 10:09:29.318: INFO/ActivityManager(607): START u0
{act=android.intent.action.VIEW dat=file:///non_existent_dummy_folder/foo.abcdef typ=application/abcdef cmp=com.foo.bar/.app.FooViewer}
Related
I am trying to make a video player app. I can play video by opening my app manually. But I want to show my app as an option like below picture:
in short, when I click any video file in file manager, this will show my app as an option for playing that video. When user click on my app this will open a particular activity and start playing that file. How can I do this?
add intent filter to activity.
very similar to this.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>
also see this Forcing an app chooser
Read how to achieve this in official documentation
You need to put an intent filter in your manifest.xml. This tells the OS which types of media/ files your app is capable of handling. When you click a video file in file manager, Android issues an implicit intent . This basically puts out a wanted ad (excuse the analogy) to other apps that the file needs to be handled. When this happens, if your app has the capability to handle this file/ media type, it will respond. From here, if there is only one capable app, it will be selected for the task. If there are multiple capable apps, all of them will be added to a list, which is then displayed to the user (the list in the image you posted above.)
Add the below code to inside activity(that you want to open) inside manifest:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="video/*"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
</intent-filter>
use below code to your activity to get the uri of your file. I have tested the path in exoplayer.
Uri uri = getIntent().getData();
I've got a file type, the extension is '.rfts' (really it's just storing a JSON string that represents user configurations for an audio amplifier). I'd like to be able to open this file when it's an attachment from an e-mail (Gmail for example) so I can import user settings from another tablet.
Here's what my manifest looks like (note that I didn't include the other activities in this, but there's 4 others that don't have intent filters).
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/RFtheme" >
<activity
android:name=".activity.MainActivity"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.OPENABLE"/>
<data android:scheme="file"/>
<data android:mimeType="*/*"/>
<data android:pathPattern="\\.rfts$"/>
<data android:host="*"/>
</intent-filter>
</activity>
<provider
android:name=".model.FileProvider"
android:authorities="com.rockfordcorp.app3sixty.provider"
android:enabled="true"
android:exported="true" >
</provider>
</application>
I've been trying several other suggested fixes from other questions, but they were for things like opening a pdf from a browser.
When I try to open a .rfts attachment in Gmail, it tells me "You don't have an app that can open this file (.rfts). Try searching google play for one that can"
I'm at a loss as to what I need to be doing here. I don't have any idea what mime Gmail would be using to open a .rfts, nor what scheme it would be using. I've tried a few different combinations but nothings really worked. I just haven't put in the magic combination of category, mimetype, pattern and scheme that Android is looking for to associate this file to my app.
EDIT some success, but not quite there yet.
The questions suggested as fixes are off the mark, and the reason is because the scheme required is actually 'content', not 'file'
The intent filter that works is
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file" android:mimeType="*/*" android:pathPattern=".*\\.rfts"/>
<data android:scheme="content" android:pathPattern=".*\\.rfts" android:mimeType="application/octet-stream" />
<!-- <data android:host="*"/> -->
</intent-filter>
Without the android:sceheme="content" it does not work.
However, a new problem arises. Gmail now opens all file types that are not previously associated with another app. For example, if I were to try to open a .rfff file, it uses my app. If you try to open a .txt it opens a chooser for Chrome or HTML viewer.
This is close, but it opening other file types is problematic. Android:pathPattern evidently has no effect on what filetype my app is associated with.
As this question was marked as a possible duplicate I want to point out the solution suggested is not working for opening a file from g-mail not web, nor does it cover opening a custom filetype. Using that 'solution' with the file type swapped out causes g-mail to continue to insist there is no app on the device capable of opening the file type.
A different solution likely needs to be provided to associate opening this custom filetype via the intent from Gmail.
Update 2020
Android has moved towards content URIs and MIME-Types for intent filters.
The Problem
A content URI does not necessarily have to contain the file's extension or name and it will be different between different applications that are providing the content/file.
Here are some example content URIs from different email applications for the same email attachment:
Gmail -> content://com.google.android.gm.sapi/some_email#gmail.com/message_attachment_external/%23thread-a%3Ar332738858767305663/%23msg-a%3Ar-5439466788231005876/0.1?account_type=com.google&mimeType=application%2Foctet-stream&rendition=1
Outlook -> content://com.microsoft.office.outlook.fileprovider/outlookfile/data/data/com.microsoft.office.outlook/cache/file-download/file--2146063402/filename.customextention
Samsung Email App -> content://com.samsung.android.email.attachmentprovider/1/1/RAW
As can see they are all different and are not guaranteed to contain anything related to your actual file. Thus, you cannot use the android:pathPattern like most have suggested.
A work around solution for email attachments
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="content"/>
<data android:host="*"/>
<!-- Required for Gmail and Samsung Email App -->
<data android:mimeType="application/octet-stream"/>
<!-- Required for Outlook -->
<data android:mimeType="application/my-custom-extension"/>
</intent-filter>
Through testing I found the MIME-Types that Gmail, Outlook, and Samsung Email used and added those to my intent-filter.
Caveats/Gotchas
I found that with my above solution, if I opened any file that was a binary type, it would automatically launch my app. I handled this in my activity by displaying a failed state if we could not parse the file. I figured this was a pretty rare event so it would acceptable.
I could not find any way to launch my app via the file browser without adding <data android:mimeType="*/*"/> to my intent-filter. I couldn't use this because it would then launch my app whenever the user clicked any file on their phone (not just the custom-file-extension ones). I would not recommend adding this to your intent-filter.
I had no luck using android:scheme="file" at all.
I tested this on a Samsung Galaxy S10 on Android 10
Final Thoughts
There is currently no elegant solution for associating your app with a specific extension type in Android. This was the best that I could do in my situation.
Hi I am trying to create an app that accepts files from other applications. I tried this tutorial, http://developer.android.com/training/secure-file-sharing/setup-sharing.html as well as this one, http://code.tutsplus.com/tutorials/android-sdk-receiving-data-from-the-send-intent--mobile-14878 and nothing seems to work.
here is my manifest,
...
<activity
android:name="com.example.activities.mainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/*" />
</intent-filter>
</activity>
...
Yet still for some reason my application won't show up if I try to share files with it from dropbox or anything else. I've tried different mime types, using SEND instead of SEND_MULTIPLE, and starting a clean application project and nothing.
Thanks
EDIT:
Essentially what I want to do is have my app show up in the share menu for all other applications. I managed to get a complete action using... pop up, but this isn't what I'm looking for. Unfortunately all google searches result in the info above.
I believe that I have solved it. for mime type rather than having "application/*" all you need is */*. For some reason, most files are opened as text/plain mime type including excel files. Odd.
I know this question is asked and answered many times on SO, but I just couldn't get it to work. Here is my manifest file (I have 3 activities, I'm showing the only one that I want to be displayed when associated):
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#style/HoloDarkTheme" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.ACTION_SEND" />
<action android:name="android.intent.action.EXTRA_TEXT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.action.BROWSABLE" />
<category android:name="android.intent.action.DEFAULT" />
<data android:scheme="http" />
<data android:host="example.com" />
</intent-filter>
</activity>
When I launch a browser and go to "example.com", my app isn't launched. Is there something wrong with the above XML?
Not sure if relevant, but this activity uses MediaPlayer to play videos. Also, I'm using SDK version 11.
I figured it out. It's simply a case of typo. Instead of this,
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.action.BROWSABLE" />
<category android:name="android.intent.action.DEFAULT" />
I needed to replace "android.intent.action" with "android.intent.category" in the last two lines:
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
I'm adding this answer here because this thread is one of the top hits when googling "intent filter to launch app from http not working". I suppose the root cause for me could also be considered a typo, but I'm going to call it an "Android documentation defect".
There's a line way toward the bottom of this page that breaks down a URI as:
<scheme>://<host>:<port>/<path>
This breakdown indicates that the "://", ":" and "/" will be added for me so I used the following data in my intent-filter:
<data android:scheme="http" />
<data android:host="my.school.edu" />
<data android:path="thingy" />
I then sent myself an SMS with the following text: "my.school.edu/thingy", which was recognized by my SMS client (Hangouts) as a web address, so it made it clickable. However, clicking on it just gave me a choice of browsers, my app was a no-show.
So I removed the host and the path, and my app launched for any link (or at least every one I tried). I put the host back in and it still worked. Put the path back and we're back to not working. On a whim I decided to prepend a slash to the path:
<data android:path="/thingy" />
...et voilĂ ! There's my app in amongst the browsers! So the error in my view is Android's doc that suggests that the slash is inserted automagically. :) It apparently is not.
More Info: I'm using the HTTP scheme because that's what gets made clickable in SMS and email messages, giving me a free ride to that point.
And note that if you specify a unique host (and path), and the user selects "Always" when choosing your app from the list, future taps on your link will bypass that choice dialog and go straight to your app, which is nice.
Make sure you have the internet permission in your manifest.
I doubt that you can override the http scheme to point back to your app.
I am having a problem getting an activity to be initiated in response to a file download from a browser window.
When I click the file download button in broswer it gets downloaded to SD card, rather than firing off my MainActivity (or even prompting what I should do with it).
If I then locate the file on the SD card using a file explorer and select it then my MainActivity is initiated.
Have I misunderstood how intent filters work? I have verified the mime type for the download file using wireshark on a pc to verify that it is as expected.
[ If i remove the PathPattern and simply have the mime type in place then when pressing the download button I am prompted saying that there is nothing on the device to handle this file and do I still want to go ahead with the download.]
Any help would be appreciated.
Here is the entry from my manifest:
<activity android:name=".activity.main.MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/xml-mydata"
android:pathPattern=".*\\.mydata" />
</intent-filter>
</activity>
Conceptually what you have seems fine, though I would dump the pathPattern. Here is a sample project demonstrating these sorts of <intent-filter> elements.
I would make sure that your MIME type has valid syntax. I forget off the top of my head if dashes are allowed.