2

I'm trying to push dynamic shortcuts to Google Assistant, as outlined here: Google's documentation.

The code runs fine, and if I tap & hold my icon in the launcher, I get the shortcut, but if I go to shortcuts in the Assistant settings, my app is not even listed...

Here's the code that creates the shortcut:

    Intent intent = new Intent(this, MainActivity.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.putExtra("Test", "Test");

    ShortcutInfoCompat.Builder scBuilder = new ShortcutInfoCompat.Builder(this, "Locate")
      .setShortLabel("Locate item")
      .setLongLabel("Locate specific item")
      .addCapabilityBinding("custom.actions.intent.LOCATE")
      .setIntent(intent);

    if (!ShortcutManagerCompat.pushDynamicShortcut(this, scBuilder.build()))
    {
        Log.d("INTENT", "Failed...");
    }

pushDynamicShortcut does not return false.

Also here's my shortcut.xml:

<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <capability
        android:name="custom.actions.intent.LOCATE"
        app:queryPatterns="@array/LocateQueries">
        <intent android:action="android.intent.action.VIEW">
        </intent>
    </capability>

    <shortcut
        android:shortcutId="Locate"
        android:shortcutShortLabel="@string/actionLocate">
        <intent
            android:targetClass="com.XXX.MainActivity"
            android:targetPackage="com.XXX" />
        <capability-binding android:key="custom.actions.intent.LOCATE">
        </capability-binding>
    </shortcut>
</shortcuts>

The app is currently published on the store, and I'm working on an update...

user1532080
  • 243
  • 2
  • 11

1 Answers1

0

The issue was the test phone was actually not on the same account as the one used to publish the app. Removed all accounts, added that one and it worked.

user1532080
  • 243
  • 2
  • 11
  • Is it possible to add dynamic shortcuts directly in "Your shortcuts" tab in Google Assistant App Settings? because as of now I am able to create shortcuts but it is display in "Explore" tab and once I click on "+" icon then that shortcut will move to "Your shortcuts" tab and I can use that shortcut. – Amit Soni Apr 26 '23 at 13:27
  • 1
    @AmitSoni I wouldn't expect it to be possible. The way I see it, this is the normal behaviour, your app offers shortcuts, then user decides to use them or not. – user1532080 May 01 '23 at 14:29