shortcuts.xml中的"android.shortcut.conversation"是什么意思?

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>

还有其他可用的值吗?我需要包含这个类别吗?如果我删除它会发生什么?

我在官方文档https://developer.android.com/guide/topics/ui/shortcuts.html中没有找到相关信息。

4个回答

7
categories标签用于为应用程序快捷方式执行的操作类型提供分组。其中一个可用的组是android.shortcut.conversation,如果您想在聊天应用程序的对话框中添加快捷方式,则可以使用该组。例如,最近的聊天头像的快捷方式。只有在需要提供所述快捷方式时,才需要将其添加到快捷方式.xml中。否则,您不需要它。您可以删除它。
对于API级别26或更低版本,这是唯一可用的值。但对于更高版本,有多个值。
有关支持的快捷方式类别列表,请参见此页面

仍然只有一个可用。https://developer.android.com/reference/android/content/pm/ShortcutInfo.html#SHORTCUT_CATEGORY_CONVERSATION - user924

2

目前只支持一种类别,即android.shortcut.conversation。您可以在ShortcutInfo中找到它。

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

同时,在

/**
     * 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;
    }

1

简而言之,到了2022年,似乎“类别”内部元素成为了Android快捷方式中被遗忘的功能,只有一个预定义的“对话”类别。另一方面,功能非常完善,可以很好地满足需求!请查看下面的链接,了解功能如何帮助您解锁!

更详细地说,截至2022年,Android API Level 25引入了定义快捷方式的功能,让您为用户提供静态集合的应用程序快捷方式,以进行常见操作,例如创建新电子邮件,以及动态集合的快捷方式,例如向最近联系人发送消息。

似乎“类别”内部元素旨在将某些相似的快捷方式分组。不幸的是,由于小弹出菜单中可以显示的快捷方式数量有限,这个想法似乎被放弃了。现在,我看到的最多的是5个,当然这可能因设备而异。由于空间有限,即使在API级别32可用的今天,似乎唯一定义的类别也是“对话”类别。

由于它的开发有限,我发现99%的时间最好不要使用“类别”内部元素,而选择具有相当长的预定义选项列表的“能力”内部元素,它对应于内置意图(可以为您的应用程序添加惊人的Google助手操作)!

这里是全部列表!


0

消息相关操作的快捷方式类别,例如聊天。


但它到底是做什么的? - Mikhail
阅读此处,或许会对你有所帮助: https://guides.codepath.com/android/Creating-App-Shortcuts-in-Launcher - itzhak levy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接