【问题标题】:configure android intents via config.xml in phonegap app通过 phonegap 应用程序中的 config.xml 配置 android 意图
【发布时间】:2014-11-17 16:06:30
【问题描述】:

我正在开发一个 phonegap,并希望将意图用于 android。当我将以下内容添加到 AndroidManifest.xml(在平台/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

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

我的phonegap版本是3.5.0-0.21.18

【问题讨论】:

    标签: android cordova webintents


    【解决方案1】:

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

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

    目前,cordova prepare android 不会删除您的意图过滤器,这意味着在当前版本的 cordova 中,只有在您删除 android 平台或升级到允许这样配置。

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

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

    【讨论】:

    • thx,写一个钩子正是我作为解决方法所做的,我想现在这根本无法通过 config.xml 完成
    • 关于 Cordova 6.0 的任何更新?仍在尝试找到正确的合成器,但到目前为止无济于事
    【解决方案2】:

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

    我在this anwser 中记录了我所做的事情。我希望这会有所帮助!

    【讨论】:

      【解决方案3】:

      我设法通过在 plugin.xml 文件中为 web 意图插件添加必要的条目来使其工作。

      即添加这个:

      <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>
      

      到这个文件:

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

      您应该已经有一个在安装插件时添加的“&lt;intent-filter&gt;”标签。如果您使用的是来自 darryncampbell 的插件(这是 Ionic 目前引用的用于 webintents 的“官方”插件),那么您会看到它是 &lt;intent-filter&gt;,它被属性 android:name="com.darryncampbell.cordova.plugin.intent.ACTION" 引用。

      在该过滤器的正下方添加您的新意图过滤器。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-26
        • 1970-01-01
        • 2017-09-25
        • 1970-01-01
        • 2019-03-01
        相关资源
        最近更新 更多