Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying a SEND (sharing) intent filter for a Service

I am trying to filter and handle intents with android.intent.action.SEND actions in one of my Services. I wrote the following in my AndroidManifest.xml:

<service 
    android:name=".app.ScreamerService"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.SEND"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="*/*"/>
    </intent-filter>                                                                    
</service>

Now, the problem is that I don't see my application in the list of "share via" options when, for instance, trying to share a web page from the browser or a contact from the list of contacts. If, however, I move the intent filters to the main <activity> tag (instead of the <service>), my application name and icon do appear on the list of "share via" options.

What am I doing wrong here? Can't a SEND action be directed to a Service?

like image 967
smichak Avatar asked Jun 18 '12 14:06

smichak


People also ask

Which component can you specify in an intent filter?

Each intent filter specifies the type of intents it accepts based on the intent's action, data, and category. The system delivers an implicit intent to your app component only if the intent can pass through one of your intent filters.

What's the difference between intent and intent filters?

An intent is an object that can hold the os or other app activity and its data in uri form.It is started using startActivity(intent-obj).. \n whereas IntentFilter can fetch activity information on os or other app activities.

Can an activity have multiple intent filters?

However, since a component can have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another. An <intent-filter> element in the manifest file lists actions as <action> subelements. For example: <intent-filter . . . >

What is the purpose of intent filter?

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.


1 Answers

I am trying to filter and handle intents with android.intent.action.SEND actions in one of my services.

ACTION_SEND is an activity action and therefore cannot be picked up by services or broadcast receivers.

Now, the problem is that I don't see my application in the list of "share via" options when, for instance,

That is because it is not an activity.

Can't a SEND action be directed to a Service?

Things that appear in a chooser (e.g.,. for ACTION_SEND) must be activities. Your activity is welcome to communicate with a service, though.

like image 196
CommonsWare Avatar answered Oct 13 '22 02:10

CommonsWare