15

I want my Android app to appear listed as an option when the user shares an URL from another app (like the browser). How can I register my app to do that? How can I react to link shares?

Thanks a lot.

Edit:

I've tried using IntentFilter like this without success:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

Any ideas?

Vlad Schnakovszki
  • 8,434
  • 6
  • 80
  • 114
David Saltares
  • 808
  • 2
  • 11
  • 19

3 Answers3

25

At the very bare minimum you need:

<activity android:name=".ShareActivity">
    <intent-filter
        android:label="Share with my app">
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

in your manifest...which will at least make it show up in the 'share' listing.

The most important part you are missing is:

<action android:name="android.intent.action.SEND" />

To make it actually do something, you need an Activity.

This may help too: http://sudarmuthu.com/blog/sharing-content-in-android-using-action_send-intent

Additional Info:

<activity android:name=".ShareActivity">
<intent-filter
    android:label="Share with my app">
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>
</activity>

There the <data android:mimeType will limit what you respond to, if you want to limit your app's response.

TryTryAgain
  • 7,632
  • 11
  • 46
  • 82
  • Thanks, that registers my app to be listed when I share an URL. However, the article you posted does not say how to respond when another app shares an URL with my app. For now, my app is open as usually, nothing special happens. How can I retrieve the shared URL? – David Saltares Dec 24 '11 at 12:25
  • 4
    Your question asked how to get it listed. You may want to accept this as an answer and post another question along the lines 'retrieve shared url from android.intent.action.SEND intent' Just a thought. – TryTryAgain Dec 24 '11 at 12:28
  • 2
    Or not: http://www.vogella.de/articles/AndroidIntent/article.html#explicitintents is what you're looking for - You should at least vote it up as it was helpful, even though it did provide a solution to your question. – TryTryAgain Dec 24 '11 at 12:38
  • 1
    Did not work on chrome despite doing everything mentioned in the documentation. If it still doesn't work for someone, refer this please: http://stackoverflow.com/a/21727055/2695276 PS: struggled for days over this. – Rajat Sharma Jan 02 '15 at 21:10
2

To get the image in your activity, use Uri imgUri = (Uri) i.getParcelableExtra(Intent.EXTRA_STREAM); for a single image, or use ArrayList<Uri> imgUris = i.getParcelableArrayListExtra(Intent.EXTRA_STREAM); for a list of images:

Intent i = getIntent();
Bundle extras = i.getExtras();
String action = i.getAction();

// if this is from the share menu
if (Intent.ACTION_SEND.equals(action)) {   
    if (extras.containsKey(Intent.EXTRA_STREAM)) {
        Uri imgUri = (Uri) i.getParcelableExtra(Intent.EXTRA_STREAM);
        // Do job here
    }
}

Hope that helps

rayryeng
  • 102,964
  • 22
  • 184
  • 193
Oluwatumbi
  • 1,321
  • 1
  • 12
  • 19
-1

You need to create an Activity with appropriate Intent filter. Read documentation about Intent, it explains all this with examples.

inazaruk
  • 74,247
  • 24
  • 188
  • 156