通过phonegap应用程序中的config.xml配置android意图

我正在开发一个phonegap,并希望使用Intent for
android.当我将以下内容添加到
AndroidManifest.xml(在platforms / android中)时,它会像预期的那样工作.

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" />
    <data android:scheme="https" />
    <data android:host="*mysite.com" />
    <data android:host="*mysite.de" />
</intent-filter>

现在我想知道如何配置这不是通过AndroidManifest.xml而是通过www /下的config.xml配置,因为据我所知,在构建过程中可能会覆盖AndroidManifest.xml文件并且config.xml是正确的位置对于像这样的东西.我尝试了以下(包括各种变化):

<platform name="android">
    <config-file target="AndroidManifest.xml" parent="/manifest/application/activity">
         <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:host="*mysite.de" />
            <data android:host="*mysite.com" />
        </intent-filter>
    </config-file>
</platform>

…遗憾的是,这将始终导致以下错误:

 [echo] ----------
 [echo] Handling Resources...
 [aapt] Found modified input file
 [aapt] Generating resource IDs...
 [aapt] /home/.../platforms/android/res/xml/config.xml:30: error: Error parsing XML: unbound prefix

感谢任何想法,我在网上搜索了一个多小时.

我的手机版本是3.5.0-0.21.18

最佳答案 使用旧版本的cordova 3,保留了androidmanifest.xml更新.当他们使用首选项标签添加更多选项时,我开始对3.5版本感到意外.

例如,我曾经通过更新AndroidManifest.xml来配置AndroidLaunchMode,现在他们添加了一个选项,允许在config.xml中进行此配置,这使得在升级cordova cli之后,我的设置消失了,直到我意识到发生了什么.

目前,cordova准备android不会删除你的意图过滤器,所以这意味着使用当前构建的cordova,你将失去你的更改只有你删除Android平台或升级到更新的cordova android,这将允许这样的配置.

如果你想确保不要松开这个设置,你可以在post-prepare中编写一个钩子来更新AndroidManifest.xml.

或者您可以创建一个只更新AndroidManifest.xml的插件(您尝试使用的配置文件语法似乎是更多的plugin.xml语法).

点赞