Reputation: 3819
I want users to be able to Share/Send to my app, but I don't want to start an activity (I just need to send some data on the network, and show a success message popup). I was imagining using a Broadcast Receiver for this, but the intent filter shown below, while it works when in a normal activity, doesn't work for a receiver (i.e. my app doesn't show in the list of things I can share to).
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</receiver>
Should I be using a receiver here, or is there some other way of catching a SEND intent without launching a full activity?
Upvotes: 2
Views: 830
Reputation: 1006799
my app doesn't show in the list of things I can share to
Correct. That is because ACTION_SEND
is used for activities. The ones who are initiating ACTION_SEND
are calling startActivity()
. You cannot respond to a startActivity()
request with anything other than an Activity
.
is there some other way of catching a SEND intent without launching a full activity?
No. You are welcome to use Theme.NoDisplay
, Theme.Translucent.NoTitleBar
, or something to have an activity with no UI, though. Just don't call setContentView()
in onCreate()
, but instead do your work (e.g., kick off an IntentService
to do your network I/O), and call finish()
.
Upvotes: 5