admin管理员组

文章数量:1289393

I implemented Dynamic Shortcuts in my app following the guides from the documentation. When using the App Actions Test Tool, logging in a device with the same account as Android Studio, everything works and I am able to open the shortcut list in Google Assistant and add the shortcut to be called with a single word.

However, when the app goes to production, this does not work. I have extracted the APK from Play Store to make sure I was sending the right one and the AndroidManifest.xml and the shortcuts.xml are identical.

For context: when in contact with the App Actions Review Team from Google, they made it clear to me that the problem is not review related. Meaning it must be some code issue. Since it works when testing, I am left to wonder what is wrong. I'd appreciate any pointers.

Manifest configuration for the main activity:

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />

  // This one here
  <data android:scheme="my_scheme" android:host="call_for_help" />
</intent-filter>

<meta-data
  android:name="android.app.shortcuts"
  android:resource="@xml/shortcuts" />

MainActivity code to push the Dynamic Shortcut:

val shortcutIntent = Intent(Intent.ACTION_VIEW, Uri.parse("my_scheme:call_for_help"))
val shortcutInfo = ShortcutInfoCompat.Builder(context, "my.package.name.help_shortcut")
  .setShortLabel("Ajuda") // Words in Portuguese
  .setLongLabel("Pedir ajuda") // Words in Portuguese
  .addCapabilityBinding("actions.intent.OPEN_APP_FEATURE")
  .setIntent(shortcutIntent)
  .setIcon(IconCompat.createWithResource(context, R.mipmap.my_icon))
  .build()

ShortcutManagerCompat.pushDynamicShortcut(context, shortcutInfo)

And the shortcuts.xml:

<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android=";>
    <capability android:name="actions.intent.OPEN_APP_FEATURE">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="my.package.name"
            android:targetClass="my.package.name.MainActivity">
            <parameter
                android:name="feature"
                android:key="feature"/>
        </intent>
    </capability>
</shortcuts>

When using the App Actions Test Tool it works. I am able to see the Dynamic Shortcut inside the shortcuts list in Google Assistant, and then add the shortcut and call it using my voice.

本文标签: androidDynamic Shortcut for Google Assistant working in testing but not in productionStack Overflow