简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM