configure android intents via config.xml in phonegap app

断了今生、忘了曾经 提交于 2019-12-10 17:16:22

问题


I am developing a phonegap and would like to use intents for android. When I add the following to AndroidManifest.xml (within platforms/android) it works like expected.

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

Now I would like to know how to configure this not via AndroidManifest.xml but via config.xml under www/ since as far as i understand the AndroidManifest.xml file might be overwritten during the build process and the config.xml is the right place for stuff like this. I tried the following (including all kinds of variations):

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

...unfortunately this will always result in the following error:

 [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

Any idea is appreciated, I searched the web for over an hour.

My phonegap version is 3.5.0-0.21.18


回答1:


With older versions of cordova 3, androidmanifest.xml updates were kept. I started to have surprises with version 3.5 when they added more options with the preference tag.

For example, I used to configure AndroidLaunchMode by updating AndroidManifest.xml and now they added an option to allow this configuration in config.xml which made that after upgrading cordova cli, my setting disapeared untill I realised what was going on.

For the moment, cordova prepare android will not delete your intent filter, so that means that with current build of cordova you will loose your changes only if you remove the android platform or you upgrade to a newer cordova android which would allow such configuration.

If you want to be sure not to loose this setting, you may write a hook in post-prepare to update AndroidManifest.xml.

Or you could make a plugin that would only update AndroidManifest.xml (the config-file syntax you're trying to use seems to be more plugin.xml syntax).




回答2:


I was facing the exact same problem. I had to use hooks as a workaround, never managed to get it right from the config.xml file itself.

I documented what I did in this anwser. I hope this helps !




回答3:


I managed to get this to work by adding the necessary entries within the plugin.xml file for the web intents plugin.

I.e. add this:

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

to this file:

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

You should already have an "<intent-filter>" tag that was added when you installed the plugin. If you're using the plugin from darryncampbell (which is the currently referenced "official" plugin for webintents from Ionic) then you'll see it as the <intent-filter> that's referenced with the attribute android:name="com.darryncampbell.cordova.plugin.intent.ACTION".

Add your new intent filter directly below that one.

The downside of this approach is that you'll likely need to re-enter the details if you reinstall the plugin. I could not get it to work by adding the entries in config.xml though.



来源:https://stackoverflow.com/questions/26976796/configure-android-intents-via-config-xml-in-phonegap-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!