Make Android app listen to shared links

David Saltares picture David Saltares · Dec 24, 2011 · Viewed 13.1k times · Source

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?

Answer

TryTryAgain picture TryTryAgain · Dec 24, 2011

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.