My question is relatively simple considering the options shown in the official documentation and code labs but i've been struggling to make it work.
I want to trigger a widget to be shown in Google Assistant via a dynamic shortcut. Seems pretty straightforward but when implementing a capability and dynamic shortcut like this:
<capability
android:name="actions.intent.GET_RESERVATION">
<app-widget
android:identifier="GET_MY_RESERVATION"
android:targetClass="com.myapp.widget.MyWidget">
<parameter
android:name="reservation.reservationFor.name"
android:key="shortcutId"
android:required="true"
app:shortcutMatchRequired="true" />
<extra android:name="hasTts" android:value="true"/>
</app-widget>
<intent
android:identifier="GET_MY_RESERVATION_FALLBACK"
android:action="android.intent.action.VIEW"
android:targetClass="com.myapp.widget.MyWidget">
</intent>
</capability>
val shortcut = ShortcutInfoCompat.Builder(context, "shortcut_id")
.setShortLabel("shortcut label"))
.setExcludedFromSurfaces(ShortcutInfoCompat.SURFACE_LAUNCHER)
.setLongLived(false)
.addCapabilityBinding(
"actions.intent.GET_RESERVATION",
"reservation.reservationFor.name",
context.resources.getStringArray(R.array.synonyms).toList()
)
.setIntent(Intent(context, MyWidget::class.java).apply {
action = Intent.ACTION_VIEW
})
.setRank(2)
.build()
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
The intent defined for the shortcut is the one triggered rather then the widget defined for the capability. Moreover, the shortcut definition above is crashing the app since it expects its intent to be something that could be invoked via startActivity()
(and a widget is not).
If i define the same shortcut statically:
<shortcut
android:shortcutId="shortcut_id"
android:shortcutShortLabel="shortcut label">
<capability-binding
android:key="actions.intent.GET_RESERVATION">
<parameter-binding
android:key="reservation.reservationFor.name"
android:value="@array/synonyms" />
</capability-binding>
</shortcut>
I can omit the intent and triggering this action will delegate the logic to the capability's widget as expected. Unfortunately I couldnt find a way to create a dynamic shortcut without an intent.
Anything im missing here? Help is appreciated.