在 manifest.xml 中 入口Activity中添加 <meta-data> 标签
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shot_shortcut" />
其中name的值是固定的,resource为shortcut具体的配置文件信息。
shot_shortcut.xml 文件具体配置如下
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="shortcut_identify" //要唯一
android:enabled="true"
android:icon="@drawable/shortcut_icon" //快捷方式图标
android:shortcutShortLabel="@string/shortcut_short" //快捷方式的短名称
android:shortcutLongLabel="@string/shortcut_long" //快捷方式的长名称,优先使用长名称
android:shortcutDisabledMessage="@string/shortcut_disabled"> //快捷方式被禁用信息
<intent
android:action="android.intent.action.VIEW" //
android:targetPackage="com.demo.shortcutsTest" //包名
android:targetClass="com.demo.shortcutsTest.MainActivity" /> //具体要跳到的类
<categories android:name="android.shortcut.conversation" /> //目前只有这个categories分类
</shortcut>
<!--每个应用最多可以注册5个Shortcuts-->
</shortcuts>
按照上面的配置基本就完成了静态快捷方式的创建了