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

configure android intents via config.xml in phonegap app

我正在开发一个phonegap,并想为Android使用Intent。 当我将以下内容添加到AndroidManifest.xml中(在platform / android中)时,它的工作原理与预期的一样。

1
2
3
4
5
6
7
8
9
<intent-filter>
   
    <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是正确的位置 对于这样的东西。 我尝试了以下操作(包括各种变体):

1
2
3
4
5
6
7
8
9
10
11
12
13
<platform name="android">
    <config-file target="AndroidManifest.xml" parent="/manifest/application/activity">
         <intent-filter>
           
            <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>

...不幸的是,这总是会导致以下错误:

1
2
3
4
5
 [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

任何想法都值得赞赏,我在网上搜索了一个多小时。

我的phonegap版本是3.5.0-0.21.18


在较旧版本的cordova 3中,保留了androidmanifest.xml更新。当他们在3.5版本中添加了带有首选项标签的更多选项时,我开始感到惊讶。

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

目前,cordova prepare android不会删除您的意图过滤器,因此这意味着使用最新版本的cordova,只有在删除android平台或升级到允许这种配置的较新的cordova android时,您才会松动更改。

如果您要确保不要丢失此设置,则可以在准备后编写钩子以更新AndroidManifest.xml。

或者,您可以制作一个仅更新AndroidManifest.xml的插件(您尝试使用的配置文件语法似乎更多是plugin.xml语法)。


我设法通过在用于Web意向插件的plugin.xml文件中添加必要的条目来使其工作。

即添加以下内容:

1
2
3
4
5
6
7
8
9
<intent-filter>
       
        <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>

到这个文件:

1
/plugins/com-darryncampbell-cordova-plugin-intent/plugin.xml

安装插件时,您应该已经添加了" "标签。如果您使用的是darryncampbell的插件(这是Ionic的Webintent的当前引用的"官方"插件),那么您会看到它是使用属性android:name="com.darryncampbell.cordova.plugin.intent.ACTION"引用的

将新的Intent过滤器直接添加到该过滤器的下面。

这种方法的缺点是,如果您重新安装插件,则可能需要重新输入详细信息。我无法通过在config.xml中添加条目来使其工作。


我正面临着完全相同的问题。我不得不使用钩子作为解决方法,从未设法从config.xml文件本身正确地获取它。

我记录了我在这个答案中所做的事情。我希望这有帮助 !