Created
July 21, 2016 15:45
-
-
Save smowden/798fcdd24d53afdb99b27b14020e1969 to your computer and use it in GitHub Desktop.
ES6 version for adding intent filters via cordova hooks on android
This file contains hidden or 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
module.exports = function (context) { | |
const fs = require('fs'); | |
const _ = require('lodash'); | |
const scheme = 'flowkey'; | |
const insertIntent = ` | |
<intent-filter> | |
<action android:name="android.intent.action.VIEW"></action> | |
<category android:name="android.intent.category.DEFAULT"></category> | |
<category android:name="android.intent.category.BROWSABLE"></category> | |
<data android:scheme="${scheme}"></data> | |
</intent-filter> | |
`; | |
const manifestPath = context.opts.projectRoot + '/platforms/android/AndroidManifest.xml'; | |
const androidManifest = fs.readFileSync(manifestPath).toString(); | |
if (!androidManifest.includes(`android:scheme="${scheme}"`)) { | |
const manifestLines = androidManifest.split(/\r?\n/); | |
const lineNo = _.findIndex(manifestLines, (line) => 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