Search code examples
javaandroidandroid-sharing

Allow user to send link from app to another person and then open app when clicked


I'm not even sure if this is possible, but this is what I would like to do.

Give the user an option to share some content (such as an inventory item). This is easy enough to do with and Intent using ACTION_SEND. However, if the other person has the same app installed the link should take them to my app and pass in what data was sent to them (so the app can show it to them). If they don't have the app, it should take them to the app store to encourage them to download the app.

Is this possible, and if so how is it done?


Solution

  • As described in this link : Create Deep Links

    You should add this in your manifest :

    <activity
        android:name="com.example.android.GizmosActivity"
        android:label="@string/title_gizmos" >
        <intent-filter android:label="@string/filter_view_http_gizmos">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
                <data android:scheme="http"
                      android:host="www.example.com"
                      android:pathPrefix="/gizmos" />
                <!-- note that the leading "/" is required for pathPrefix-->
            </intent-filter> 
    </activity>
    

    and then share a link that starts with "http://www.example.com/gizmos" (fake url) with another person.