androidapp-actions

How do I set up assistant shortcut suggestions with actions.intent.OPEN_APP_FEATURE?


So I'm just wondering why my code isn't working. How do I give AppShorcutIntent a specific intent with an action and data and stuff like that?

This is my code so far:

            val appShortcutIntent = AppShortcutIntent.builder()
                .setIntentName("actions.intent.OPEN_APP_FEATURE")
                .setPackageName("com.app.name")
                .setIntentParamName("feature")
                .setIntentParamValue("")
                .build()
            shortcutsClient.lookupShortcut(appShortcutIntent)
                .addOnSuccessListener { shortcutLookupResult ->
                    if (shortcutLookupResult.isShortcutPresent) {
                        shortcutsClient.createShortcutSettingsIntent().addOnSuccessListener { intent ->
                            requireActivity().startActivity(intent)
                        }
                        return@addOnSuccessListener
                    }
                    val signalShortcut = AppShortcutSuggestion.builder()
                        .setAppShortcutIntent(appShortcutIntent)
                        .setCommand("feature on")
                        .build()
                    shortcutsClient.createShortcutSuggestionIntent(signalShortcut).addOnSuccessListener { intent ->
                        requireActivity().startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
                    }
                }

I have tried so many different things and none of it seems to want to work the way I want. I know the question doesn't have anything specific as the parameter value but no matter what I set the param value too it still just doesn't get recognized as a unique intent when I use the shortcut.


Solution

  • The in-app promo library API doesn't deal with Android intents. It deals with Assistant's built-in intents, which are an entirely different things (even though they are both called "intents"). In the example you copied, it refers to the BII called OPEN_APP_FEATURE.

    By using this API, you are telling Assistant how to create a shortcut that launches the app using a BII that it is already configured to handle. This BII is important because it carries the ability to recognize natural language queries associated with it. Android intents don't have that context.