Morariu
Morariu

Reputation: 384

Adding intent filter into config.xml so that is inserted correctly in AndroidManifest.xml (Ionic 2)

I want to use Android app links to link my app with my web site. I am having issues adding intent filters (correctly) so that they're written to the AndroidManifest.xml when adding Android platform. This is in a Cordova/Ionic app.

Any suggestions are highly appreciated :slight_smile:

Here is my intent filter:

<intent-filter android:autoVerify="true">
<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" android:host="www.mydomain.com" />
<data android:scheme="https" android:host="www.mydomain.com" />
</intent-filter>

And how I was adding to add in config.xml

<platform name="android">
<config-file target="AndroidManifest.xml" parent="./application/activity/[@android:name='MainActivity']">
<intent-filter android:autoVerify="true">
<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" android:host="www.mydomain.com" />
<data android:scheme="https" android:host="www.mydomain.com" />
</intent-filter>	
</config-file>
<config-file target="AndroidManifest.xml" parent="./" mode="add">
<application android:name="customApplication"></application>
</config-file>
</platform>

It did work with https://github.com/dpa99c/cordova-custom-config plugin however the only way to insert it was the code below. It adds a second activity inside the Main Activity but it works fine.

<platform name="android">
    <config-file parent="application/activity" target="AndroidManifest.xml">
        <activity android:label="webIntentFilter" android:name="com.mydomain.myapp">
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:host="www.example.com" android:scheme="http" />
                <data android:host="www.example.com" android:scheme="https" />
            </intent-filter>
        </activity>
    </config-file>
</platform>

Upvotes: 1

Views: 2406

Answers (1)

DaveAlden
DaveAlden

Reputation: 30356

You have the correct syntax in your <config-file> block for intent-filters but unless you add the cordova-custom-config plugin to your project, the <config-file> block won't do anything since Cordova CLI only supports <config-file> blocks in the plugin.xml of plugins (not config.xml).

Hence cordova-custom-config is required to facilitate the application of custom config from within config.xml.

Once you've installed the plugin, your config should be applied to AndroidManifest.xml on the next Cordova prepare operation.

Note that the example project for the plugin contains some examples of custom intent filters.

You will need to set the application name attribute using a <preference> rather than <config-file>:

<preference name="android-manifest/application/@android:name" value="customApplication" />

Upvotes: 3

Related Questions