Notification Interactions

A user can interact with a notification by:

  • Tapping the notification

  • Clicking one of the buttons on the notification

The result of any of those interactions depends on the action you select on the Notification Message Template. There are three options:

  • Open App: launches the main activity.

  • Open Deep Link: launches an activity using an intent with action set to Intent.ACTION_VIEW and the data field set to the deep link. If this deep link can be handled by an activity in your application, that activity will be launched with the intent. Otherwise, he launched activity will depend on the installed applications on the device.

  • Open URL: launches an activity using an intent with action set to Intent.ACTION_VIEW and the data field set to the url. The actual activity that is launched depends on the url and the installed applications on the device. In most cases, urls with http/https scheme will be opened in the browser.

Handling all notification Interactions

If you need to capture all notification interactions, you can implement a BroadcastReceiver and register it with an <intent-filter> to receive all intents with action com.bird.broadcast.NOTIFICATION .

You can also access the custom payload on all notification interaction captured in BroadcastReceiver using bird.notifications.getNotificationInteraction(intent) .

Create BroadcastReceiver :

class MyBroadcastReceiver : BroadcastReceiver() {
 
    override fun onReceive(context: Context, intent: Intent) {
        when (intent.action) {
            "com.bird.broadcast.NOTIFICATION" -> handleNotificationInteractionIntent(
                context,
                intent
            )
        }
    }

    private fun handleNotificationInteractionIntent(context: Context, intent: Intent) {
        val bird = Bird(context)
        val notificationInteraction = bird.notifications.getNotificationInteraction(intent)
    }
}

Register your BroadcastReceiver as a <receiver> inside your AndroidManifest.xml:

<application>

    <!-- Add <receiver> inside <application> -->
    <receiver
        android:name=".MyBroadcastReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="com.bird.broadcast.NOTIFICATION" />
        </intent-filter>
    </receiver>
    
</application>

In order to receive deep links into your main activity (or another activity), you need to define an <intent-filter> on your main activity (or another activity) as follows.

<activity
    android:name=".MainActivity"
    android:exported="true">

    <!-- Add this intent-filter for deep linking -->
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        
        <!-- You can add various conditions here: scheme, host, pathPrefix, etc -->
        <data android:scheme="something" />
    </intent-filter>

</activity>

You can specify various filters including scheme, host, pathPrefix, etc. Read more about Creating deep links in Android.

Custom Payload

You can set a custom payload on the Notification Message Template to be delivered to your app. You can capture custom payload in two places:

  • When a notification interaction is received by a BroadcastReceiver. See above.

  • When a deep link launches your activity.

In both cases, you can get the custom payload by using the method bird.notifications.getNotificationInteraction(intent) . The custom payload exists on notificationInteraction.payload.

Here is how it looks like when a deep link launches your activity:

class MainActivity : ComponentActivity() {
    private var bird: Bird? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        bird = Bird(applicationContext)
        super.onCreate(savedInstanceState)

        val notificationInteraction = bird?.notifications?.getNotificationInteraction(intent)
        notificationInteraction?.payload
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        intent?.let {
            val notificationInteraction = bird?.notifications?.getNotificationInteraction(intent)
            notificationInteraction?.payload
        }
    }
}

Last updated