【发布时间】:2018-09-21 05:35:36
【问题描述】:
与edit-config is not working in config.xml in cordova相关
❯ cordova --version
6.5.0
我想在AndroidManifest.xml中添加如下配置
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
我检查了the official cordova docs,下面是这个例子
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.foo.Foo" android:label="@string/app_name">
<intent-filter></intent-filter>
</activity>
</config-file>
所以我将以下块添加到我的config.xml 文件中
<config-file target="AndroidManifest.xml" platform="android" parent="/manifest/application/activity" mode="merge">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</config-file>
????没有任何成功。
注意:我使用this plugin darryncampbell-cordova-plugin-intent,它在其plugin.xml 文件中使用config-file 标签。但是同一标签在 config.xml 文件中不起作用。
到目前为止一切顺利,我更努力地尝试了另一个文档。如the deprecated plugin cordova-plugin-intent中所述
建议使用钩子或自定义配置插件,以确保上述 XML 将自动添加,以防您想要重新结帐或删除/添加平台。
所以我去了the recommended plugin cordova-custom-config,也列出了the related question about edit-config tag。还有the documentation of this plugin tells me the exact same as the official cordova documentation about config-file tag in config.xml
但是:最新版本的 Cordova/Phonegap CLI 在 config.xml 中添加了官方支持和块(以前它们只在 plugin.xml 中工作)。
因此,如果您只想插入一个原生配置块或更改原生偏好,那么您可能根本不需要这个插件。
我成功使用edit-config将自定义属性从config.xml合并到AndroidManifest.xml,如下图绿色部分。
但是我还是不知道怎么用config-file更新AndroidManifest.xml如上图红色部分。
❓ 所以问题是:关于config-file 的科尔多瓦文档有误吗? 2018年将自定义intent-filter添加到AndroidManifest.xml的最佳解决方案是什么?
我加了config.xml
<platform name="android">
<allow-intent href="market:*" />
<custom-config-file target="AndroidManifest.xml" parent="./application/activity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</custom-config-file>
</platform>
插件将自定义配置从config.xml 应用到AndroidManifest.xml
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="com.darryncampbell.cordova.plugin.intent.ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
但是自定义的intent-filter 没有附加到intent-filter 列表中,而是替换了第一个
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.darryncampbell.cordova.plugin.intent.ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
【问题讨论】: