Android长按图标展示快捷方式

发布时间:2023年12月31日
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                new Thread(() -> {
                    // 获取ShortcutManager实例
                    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

                    // 创建要添加的快捷方式
                    ShortcutInfo.Builder shortcutBuilder = new ShortcutInfo.Builder(Chat1Activity.this, "shortcut_id")
                            .setShortLabel("查看便签")
                            .setLongLabel("查看便签列表")
                            .setIcon(Icon.createWithResource(Chat1Activity.this, R.drawable.ic_launcher))
                            .setIntent(new Intent(Chat1Activity.this, NoteActivity.class).setAction(Intent.ACTION_VIEW));

                    // 添加快捷方式到ShortcutManager
                    ShortcutInfo shortcutInfo = shortcutBuilder.build();
                    shortcutManager.setDynamicShortcuts(Arrays.asList(shortcutInfo));
                }).start();
//                NoteActivity.open(this);
            }
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">

    <shortcut
        android:enabled="true"
        android:icon="@mipmap/ic_launcher"
        android:shortcutId="note_list"
        android:shortcutShortLabel="@string/shortcut_note_list">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="org.lightning.chat.note.NoteListActivity"
            android:targetPackage="org.lightning.chat" />
        <categories android:name="android.shortcut.conversation" />
        <capability-binding android:key="actions.intent.CREATE_MESSAGE" />
    </shortcut>

    <shortcut
        android:enabled="true"
        android:icon="@mipmap/ic_launcher"
        android:shortcutId="add_note"
        android:shortcutShortLabel="@string/shortcut_note_add">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="org.lightning.chat.note.NoteContentActivity"
            android:targetPackage="org.lightning.chat" />
        <categories android:name="android.shortcut.conversation" />
        <capability-binding android:key="actions.intent.CREATE_MESSAGE" />
    </shortcut>

    <!--enabled, 表示这个shortcut是否可用
    icon为快捷图标
    shortcutId, 快捷方式唯一的id
    shortcutShortLabel, 短名称
    shortcutLongLabel, 这里是配置的长名称, launcher会优先选择长名称显示,显示不下会选择短名称
    categories 为应用程序的快捷方式执行的操作类型提供分组,例如创建新的聊天消息
    capability-binding 可选 声明与此快捷方式关联的功能。CREATE_MESSAGE 声明的功能,是与应用有关的 Action 内置 intent。用户可以结合使用语音指令与 Google 助理来调用此快捷方式。
    -->
</shortcuts>
 <meta-data
                android:name="android.app.shortcuts"
                android:resource="@xml/shortcuts" />

?

Android长按图标展示快捷方式 - 掘金

Android桌面长按图标快捷方式——Shortcuts_rn app 桌面长按图标快捷方式-CSDN博客

文章来源:https://blog.csdn.net/xiaoerbuyu1233/article/details/135319832
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。