Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ES5 version for adding intent filters via cordova hooks on android
'use strict';
module.exports = function (context) {
var fs = require('fs');
var _ = require('lodash');
var scheme = 'flowkey';
var insertIntent = '\n <intent-filter>\n <action android:name="android.intent.action.VIEW"></action>\n <category android:name="android.intent.category.DEFAULT"></category>\n <category android:name="android.intent.category.BROWSABLE"></category>\n <data android:scheme="' + scheme + '"></data>\n </intent-filter>\n ';
var manifestPath = context.opts.projectRoot + '/platforms/android/AndroidManifest.xml';
var androidManifest = fs.readFileSync(manifestPath).toString();
if (!androidManifest.includes('android:scheme="' + scheme + '"')) {
var manifestLines = androidManifest.split(/\r?\n/);
var lineNo = _.findIndex(manifestLines, function (line) {
return line.includes('@string/activity_name');
});
manifestLines.splice(lineNo + 1, 0, insertIntent);
fs.writeFileSync(manifestPath, manifestLines.join('\n'));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment