Deep Linking Guide
Deep Linking Guide
Push Notifications alert a user about incoming chat messages and Watch Parties. When the user clicks on the notification it will open your app by default, but for the best experience you want to have the app bring up the StreamLayer overlay for easier navigation. This is called Deep Linking. Please follow this guide to implement Deep Linking. Deep Linking is also how we handle inviting new friends into your Watch Parties. Please see the Invites Guide here.
Deep Link Integration
Each push notification from StreamLayer will add an extra payload as a PendingIntent. By implementing the PendingIntent when the user taps on the notification, the PendingIntent will trigger the launch of your app's host activity and deliver the payload to the StreamLayerFragment.
Add intent-filter to your host activity.
Use the predefined intent-filter to invoke the activity where the 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>We use a custom scheme streamLayer and path prefix /main so we can directly invoke the activity from the PendingIntent. The value in ${applicationId} will be automatically link to your applicationId from app/build.gradle so you don't need to change it here.
Forward the payload to the StreamLayer
In your host activity (like MainActivity) add the deep link handler functions to onResume() and onNewIntent. The StreamLayer.handleDeepLink() will find the StreamLayerFragment based on its tag and forward the payload to it. If this was not intent originated from StreamLayer SDK, the function will return the value of 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
}
}
}Examples of usage Deep linking can be found here
Updated 6 months ago
