Search code examples
androidandroid-jetpack-composeandroid-deep-link

Open composable screen from notification using deeplink Android 13


Android 13 Device

I am trying to open a composable screen from using a deeplink from a notification. However, the browser app keeps opening instead of the app and then navigating to the correct screen.

I have the following composable screen where I am specifying the deeplinks.

    composable(
        route = "event_screen?id={id}&menuActionType={menuActionType}",
        arguments = listOf(navArgument("id") {
            type = NavType.StringType
            nullable = true
            defaultValue = null
        }, navArgument("menuActionType") {
            type = NavType.StringType
            defaultValue = AgendaMenuActionType.OPEN.name
        }),
        deepLinks = listOf(navDeepLink {
            this.uriPattern = "https://androidbox.me/event_screen/{id}"
            action = Intent.ACTION_VIEW
        })
    )
    

In my AlarmReceiver I am creating the pending Intent to be used in the notification. The notification triggers ok, but when I tap on it will open the browser app.

    val agendaIntent = Intent(
        Intent.ACTION_VIEW,
        Uri.parse("https://androidbox.me/event_screen/597ef216-2ec6-435b-9a48-cfcf0e3caa46"))

    val pendingIntent = TaskStackBuilder.create(context).run {
        this.addNextIntentWithParentStack(agendaIntent)
        this.getPendingIntent(agendaId.hashCode(), PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_CANCEL_CURRENT)
    }

    val notification = NotificationCompat.Builder(context, channelId)
        .setContentTitle(title)
        .setContentText(description)
        .setSmallIcon(R.drawable.bell)
        .setAutoCancel(true)
        .setContentIntent(pendingIntent)
        .build()

    notificationManager.notify(agendaId.hashCode(), notification)

And in my manifect I have specified like this:

   <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="androidbox.me"
            android:scheme="https">
        </data>
    </intent-filter>

What happens when I tap the notification it opens the browser.

Testing with the following

./adb shell am start -W -a android.intent.action.VIEW -d https://androidbox.me/event_screen/597ef216-2ec6-435b-9a48-cfcf0e3caa46
Starting: Intent { act=android.intent.action.VIEW dat=https://androidbox.me/... }
Status: ok
LaunchState: WARM
Activity: com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity
TotalTime: 140
WaitTime: 147
Complete

Solution

  • The answer was to have the following in the manifest as this is a deeplink not a applink

               <intent-filter android:autoVerify="true">
                    <data
                        android:host="androidbox.me"
                        android:scheme="busbyapp">
                    </data>
                </intent-filter>