Last active
December 31, 2016 14:04
-
-
Save smowden/f863331034bf300b960beef1ae25bf82 to your computer and use it in GitHub Desktop.
ES5 version for adding intent filters via cordova hooks on android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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