Android O固定快捷方式 - CREATE_SHORTCUT意图过滤器

Ori*_*man 6 java notifications android android-8.0-oreo

Android O中新的"固定快捷方式"功能的文档中,他们提到"您还可以创建一个专门的活动,帮助用户创建快捷方式,完成自定义选项和确认按钮".

我尝试按照文档进行操作,但是当我尝试创建新的快捷方式时,我只看到了默认对话框,而不是我的活动.

这是Manifest中的声明:

    <activity android:name=".ShortcutActivity">
        <intent-filter>
            <action android:name="android.intent.action.CREATE_SHORTCUT"/>
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

PS
在文档中,他们还在Gmail应用程序中显示了一个示例 - 如何进入该屏幕?我想看看流程,但我找不到它.

war*_*ero -3

创建一个新的资源文件:res/xml/shortcuts.xml。这就是创建快捷方式的方式,在清单中完成必要的更改后

<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="your package"
          android:targetClass="com.example.myapplication.ComposeActivity" />
         </shortcut>
      <!-- Specify more shortcuts here. -->
    </shortcuts>
Run Code Online (Sandbox Code Playgroud)

清单中将其添加到活动标记中,

<meta-data android:name="android.app.shortcuts"
                 android:resource="@xml/shortcuts" />
Run Code Online (Sandbox Code Playgroud)

如果您想了解更多信息,请参阅此文档,它解释了固定快捷方式、静态和动态快捷方式。

这是来自谷歌的示例,在他们的示例存储库中