是否有可能定义多个版本的静态快捷方式而不重复复制shortcuts.xml文件? 我有两个版本:
- 主要版本 (包名:com.test)
- 免费版本 (包名:com.test.free)
shortcuts.xml如下所示:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@drawable/ic_shortcut_add_photo"
android:shortcutId="new_photo"
android:shortcutLongLabel="@string/new_photo"
android:shortcutShortLabel="@string/new_photo">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.test.MainActivity"
android:targetPackage="com.test"/>
</shortcut>
问题在于Intent中的包名不能引用字符串资源,必须在xml中硬编码。
为了为免费版本提供快捷方式,我需要复制shortcuts.xml并将targetPackage更改为com.test.free,这是一个不好的解决方案。