Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent filter for files only

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.

like image 683
Snicolas Avatar asked Sep 03 '12 12:09

Snicolas


People also ask

In which file is intent filter tag used?

Intent filters are declared in the Android manifest file.

What does an intent filter do?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.

Can an activity have multiple intent filters?

If it fails to match even one of them, the Android system won't deliver the intent to the component. However, because a component may have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another filter.

What is intent filter category?

Categories are used for implicit Intents. So, If your Activity can be started by an implicit Intent when no other specific category is assigned to activity, activity's Intent filter should include this category. (even if you have other categories in the Intent filter).


Video Answer


2 Answers

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.

like image 115
CommonsWare Avatar answered Oct 21 '22 08:10

CommonsWare


  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
like image 31
rds Avatar answered Oct 21 '22 06:10

rds