Deep Linking Guide

Handle push notification deep links in the StreamLayer Android SDK. Configure PendingIntent payloads, add intent filters, and route users directly to the StreamLayer Element from notifications.

Deep Linking Guide

Push notifications alert users about incoming chat messages and Watch Party invitations. When a user taps a notification, your app opens by default. For the best experience, implement deep linking so the app navigates the user directly to the StreamLayer Element.

Deep linking is also how Watch Party invitations work. For invite-specific setup, see the Invites Guide.

Deep Link Integration

Each push notification from StreamLayer includes an extra payload as a PendingIntent. When the user taps the notification, the PendingIntent launches your app's host activity and delivers the payload to the StreamLayerFragment.

Add an Intent Filter to Your Host Activity

Use the predefined intent filter to invoke the activity where StreamLayerFragment is located:

<application>

         <!-- your host activity with StreamLayerFragment -->
        <activity
            android:name=".ui.LiveActivity"
            android:launchMode="singleTask"
            android:windowSoftInputMode="adjustResize">

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data
                    android:host="${applicationId}"
                    android:pathPrefix="/main"
                    android:scheme="streamlayer" />
            </intent-filter>

        </activity>

</application>

The custom scheme streamlayer and path prefix /main invoke the activity directly from the PendingIntent. The ${applicationId} value automatically links to your applicationId from app/build.gradle.

Forward the Payload to StreamLayer

In your host activity, add deep link handler functions to onResume() and onNewIntent(). The StreamLayer.handleDeepLink() method finds the StreamLayerFragment by its tag and forwards the payload. If the intent did not originate from the StreamLayer SDK, the function returns false.

class LiveActivity: AppCompatActivity() {
/**
     * Add a deep link handler which will listen if the activity is started from StreamLayer feature
     * and will automatically open the deep link destination in one of the StreamLayer overlays.
     *
     * Returns true if the intent was handled by StreamLayer SDK, otherwise false.
     */
    override fun onResume() {
        super.onResume()
        if (!StreamLayer.handleDeepLink(intent, this)) {
            // do host logic if needed
        }
    }

    /**
     * If your activity launch mode is set to [Intent.FLAG_ACTIVITY_SINGLE_TOP] or [Intent.FLAG_ACTIVITY_SINGLE_TASK],
     * listen for [onNewIntent] as well because the [onResume] will not be triggered if the activity is already running.
     */
    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        if (intent == null) return
        if (!StreamLayer.handleDeepLink(intent, this)) {
            // do host logic if needed
        }
    }
}

For a complete example, see the demo app.


Related