多种口味的静态android快捷方式? [英] Static android shortcuts for multiple flavors?
问题描述
是否可以为多种样式定义静态快捷方式,而无需复制shorts.xml?我有两种口味:
Is it possible to define static shortcuts for multiple flavors without duplicating the shortcuts.xml ? I have two flavors:
- 主要(软件包: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>
问题在于,意图中的程序包名称不能引用字符串资源,必须在xml中进行硬编码.
The problem is that the package name in the intent can not refer to a string resource and must be hardcoded in the xml.
要提供免费版本的快捷方式,我必须复制 shortcuts.xml ,然后将 targetPackage 更改为com.test.免费,这是一个糟糕的解决方案.
To also provide the shortcuts for the free flavor i have to copy the shortcuts.xml and change the targetPackage to com.test.free which is a bad solution.
推荐答案
我创建了一个插件,该插件可以在资源中使用manifestPlaceholders,并且可与Android gradle插件的3.0.0版本一起使用
I created a plugin which make it possible to use manifestPlaceholders in resources and is usable with version 3.0.0 of the android gradle plugin
https://github.com/timfreiheit/ResourcePlaceholdersPlugin
src/main/res/shortcuts.xml:
src/main/res/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="${applicationId}"/>
</shortcut>
这篇关于多种口味的静态android快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!