要想实现此功能,首先新建1个命名为shortcuts的XMI脚本(必须命名为"shortcu
t"
示例如下(将文件放入layout目录中)
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="显示图标"
android:shortcutDisabledMessage="@string/disable_hint_message"
android:shortcutId="shortcut1"
android:shortcutLongLabel="@string/long_label_one"
android:shortcutShortLabel="@string/short_label_one">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.example.helloworld.RecyclerViewTestActivity"
android:targetPackage="com.example.helloworld">
<extra
android:name="key1"
android:value="value1" />
</intent>
</shortcut>
<shortcut
android:enabled="true"
android:icon="显示图标1"
android:shortcutDisabledMessage="@string/disable_hint_message"
android:shortcutId="shortcut2"
android:shortcutLongLabel="@string/long_label_two"
android:shortcutShortLabel="@string/short_label_two">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.example.helloworld.TestViewPagerActivity"
android:targetPackage="com.example.helloworld">
<extra
android:name="key2"
android:value="value2" />
</intent>
</shortcut>
</shortcuts>
<string name="short_label_one">名称</string>
<string name="short_label_two">名称1</string>
<string name="long_label_one">附名称</string>
<string name="long_label_two">附名称1</string>
<string name="disable_hint_message">你确认要禁用该快捷方式吗?</string>
第二步,在软件目录AndroidManifest中添加以下代码(适当行列)
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="文件路径" />
</activity>
工程基本完成