将动态快捷方式推送到 android 上的 google 助手

Pushing dynamic shortcut to google assistant on android

我正在尝试将动态快捷方式推送到 Google 助手,如下所述:Google's documentation

代码运行正常,如果我在启动器中点击并按住我的图标,我会得到快捷方式,但如果我转到助手设置中的快捷方式,我的应用程序甚至都没有列出...

这是创建快捷方式的代码:

    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 不会 return false。

这也是我的 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>

该应用程序目前已在商店中发布,我正在进行更新...

问题是测试 phone 实际上与用于发布应用程序的帐户不同。删除了所有帐户,添加了一个并且有效。