4
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
  <shortcut
    android:shortcutId="compose"
    android:enabled="true"
    android:icon="@drawable/compose_icon"
    android:shortcutShortLabel="@string/compose_shortcut_short_label1"
    android:shortcutLongLabel="@string/compose_shortcut_long_label1"
    android:shortcutDisabledMessage="@string/compose_disabled_message1">
    <intent
      android:action="android.intent.action.VIEW"
      android:targetPackage="com.example.myapplication"
      android:targetClass="com.example.myapplication.ComposeActivity" />
    <!-- This -->
    <categories android:name="android.shortcut.conversation" />
  </shortcut>
</shortcuts>

What other value is available? Do I need to include this category and what if I delete it?

I did not find this in the official documentation - https://developer.android.com/guide/topics/ui/shortcuts.html

Mikhail
  • 2,612
  • 3
  • 22
  • 37

4 Answers4

7

categories tag is used to provide a grouping for the types of actions that your app's shortcuts perform. One of the available groups is android.shortcut.conversation, and this is used if you want to add a shortcut to conversation of chat application. For example, a shortcut to the most recent chat head. You would only need to add this in your shortcuts.xml, when you want to provide the said shortcut. Otherwise you don't need it. You can delete it. For API level 26 or lower this is the only value that is avaliable. But for higher versions there are multiple.

For a list of supported shortcut categories you can see this page.

Sam
  • 2,935
  • 1
  • 19
  • 26
  • there is still only one available https://developer.android.com/reference/android/content/pm/ShortcutInfo.html#SHORTCUT_CATEGORY_CONVERSATION – user924 Feb 13 '23 at 12:39
2

At this moment only one type supported category is android.shortcut.conversation. You can find it in ShortcutInfo

/**
 * Shortcut category for messaging related actions, such as chat.
 */
public static final String SHORTCUT_CATEGORY_CONVERSATION = "android.shortcut.conversation";

Also in

/**
     * Sets categories for a shortcut.  Launcher apps may use this information to
     * categorize shortcuts.
     *
     * @see #SHORTCUT_CATEGORY_CONVERSATION
     * @see ShortcutInfo#getCategories()
     */
    @NonNull
    public Builder setCategories(Set<String> categories) {
        mCategories = categories;
        return this;
    }
a23sokolov
  • 603
  • 3
  • 11
1

TL;DR in 2022: Seems like the "category" inner element became a forgotten feature of Android Shortcuts, and there only ended up being that one pre-defined "Conversation" category. Capabilities, on the other hand, are very well fleshed out and fill those boots quite well! Check out the link below for what capabilities can help you unlock!

In more detail as of 2022, Android API Level 25 introduced the ability to define shortcuts, letting you provide the user with a static set of shortcuts into your app for common actions like creating a new email as well as a dynamic set of shortcuts like sending a message to a recent contact.

It seems that the "category" inner element was intended to group certain similar shortcuts together. Unfortunately it seems the idea was abandoned likely due to the limited number of shortcuts that could appear in the small popup menu. These days the most I've seen is 5, and it can definitely vary based on your device. As a result of the limited space, it seems the only category that has been defined, even today with API level 32 available, is the "Conversation" category.

Due to its limited development, I find it best 99% of the time to leave off the "category" inner element in favor of the "capability" inner element which has quite the long list of pre-defined options that correspond to Built-In Intents (which can add amazing Google Assistant actions to your app)!

Here's the list of all of them!

Nick C
  • 141
  • 1
  • 5
0

Shortcut category for messaging related actions, such as chat.