13
votes

in our app, we want to appear in the "Share via" menu. So we added this intent-filter to our activity :

<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="application/*" />
    <data android:mimeType="audio/*" />
    <data android:mimeType="image/*" />
    <data android:mimeType="text/*" />
    <data android:mimeType="video/*" />
</intent-filter>

It works and our app appears in the Share menu.

Nevertheless, the intent filter doesn't do exactly what we want to achieve :

  1. we want to appear in the menu for all files, whatever there mime type is
  2. we want to appear only for files. And up to now, if the user wants to share a simple text, as its mime type will be text/plain, our app appears in the menu and we don't want it.

What would the correct intent-filter be for all files and only for files ?

Thanks in advance.


We tried to add scheme=file and host="" or "*" and it doesn't work as many app use a scheme=content to share file based content.

2
Sorry for bringing up an old question, I tried using category "android.intent.category.OPENABLE" and seems working. It doesn't show sharing a webpage from chrome, it shows sharing files from Solid Explorer. Is it safe to use this or it's better with schemes? - Giorgio Aresu
@Giorgio Aresu, it's not clear what you are asking. Did you try both options ? - Snicolas
I tried both. With schemes as mentioned in answers my doesn't even show when sharing, with openable as category it works sharing a file from a file manager but not sharing plain text from a browser. This is what I want: get files (all mime types), only files (not text), exactly what you wanted in your question. Further testing showed that some app (photoshop express, gallery) share uris as plain text or with formats like "image:3710" that don't work with openable category. I'm trying to figure it out... - Giorgio Aresu

2 Answers

7
votes

we want to appear in the menu for all files, whatever there mime type is

Try a MIME type of */*.

we want to appear only for files. And up to now, if the user wants to share a simple text, as its mime type will be text/plain, our app appears in the menu and we don't want it. We tried to add scheme=file and host="" or "*" and it doesn't work as many app use a scheme=content to share file based content.

Then have two <data> elements, one for a scheme of content and one for a scheme of file.

<data android:mimeType="*/*" />
<data android:scheme="content" />
<data android:scheme="file" />

However, bear in mind that a content scheme does not mean that it is necessarily a file.

1
votes
  1. If you want to be invoked for any mime type, don't place a single mine type in the filter
  2. scheme="file" is the answer to run only on files. Now if the 3rd party applicaiton pass the data as content, then it is (by defiinition) not a file any more