I'd like to enable a "silent send" from my application-- that is, I'd like to catch the SEND intent in a Service, not an Activity. How does the default Android web browser send that intent? Is it possible to handle it in a Service, or in an Activity that never sets a View?
A:
Services are just as capable of receiving and processing Intents as Activity classes, and they are defined in the same fashion through the <intent-filter>
tag of the Manifest. Something like
<service>
<intent-filter>
<action android:name="android.intent.action.SEND">
</intent-filter>
</service>
in your Application Manifest would do the trick.
As far as I'm aware, the Browser app does not create any SEND intents on user actions. What events are you expecting to capture from someone using the Browser?
Wireless Designs
2010-07-23 18:05:02
If you open the menu in the browser, select more, and select "Share", the browser will use a SEND intent to open the application. Thanks for the info, though. :)
Paddy Foran
2010-07-25 09:26:27
Mark is right, the ACTION_SEND intent is an activity intent, so you should probably go with a headless activity if that is the intent you must process. Be sure to qualify it with the right category/metadata tags in your intent filter so your app isn't trying to process every ACTION_SEND the user might create.
Wireless Designs
2010-07-26 17:46:35
Thanks. I ended up using finish() to close the Activity. :)
Paddy Foran
2010-07-28 20:25:55
+1
A:
Is it possible to handle it in a Service, or in an Activity that never sets a View?
ACTION_SEND
Intents
are sent as activity intents (e.g., startActivity()
), and so you cannot have a Service
receive them. You can have them handled by an Activity
that never calls setContentView()
, though.
CommonsWare
2010-07-23 18:16:23
Wireless Designs has an opposing answer (below). I'm not sure who's right... I'll just have to try both. Thanks!
Paddy Foran
2010-07-25 09:27:17