这段代码实际上是从https://developers.google.com/assistant/app/in-app-promo-sdk复制的,但它仍然不起作用有谁知道为什么这对我不起作用?
val feature: HashMap<String, Any?> = HashMap()
feature["@type"] = "MenuItem"
feature["@context"] = "http://schema.googleapis.com"
feature["name"] = "signal on"
val appShortcutIntent = AppShortcutIntent.builder()
.setIntentName("actions.intent.ORDER_MENU_ITEM")
.setPackageName("com.app.package")
.setIntentParamName("menuItem")
.setIntentParamValue(feature)
.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("signal on")
.build()
shortcutsClient.createShortcutSuggestionIntent(signalShortcut).addOnSuccessListener { intent ->
requireActivity().startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
}
}