Skip to content

Commit 4ddf036

Browse files
authored
Merge pull request #300 from BranchMetrics/fix-intent-override
Fix intent override
2 parents 467d805 + 7891eb1 commit 4ddf036

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "branch-cordova-sdk",
33
"description": "Branch Metrics Cordova SDK",
44
"main": "www/branch.js",
5-
"version": "2.5.8",
5+
"version": "2.5.9",
66
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
77
"repository": {
88
"type": "git",
@@ -38,7 +38,7 @@
3838
"scripts": {
3939
"commitmsg": "validate-commit-msg",
4040
"precommit": "gulp prod",
41-
"postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/updateNpmVersion'",
41+
"prepush": "semantic-release pre --verifyRelease='./src/scripts/npm/updateNpmVersion'",
4242
"prerelease": "gulp prod",
4343
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
4444
},

plugin.template.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.5.8">
27+
version="2.5.9">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.5.8">
27+
version="2.5.9">
2828

2929
<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->
3030

src/scripts/android/updateAndroidManifest.js

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
}
2828

2929
// adds to <application> for Branch init and testmode:
30-
// <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_icCccJIpd7GlYY5oOmoEtpafuDiuyXhT" />
31-
// <meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
30+
// <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_icCccJIpd7GlYY5oOmoEtpafuDiuyXhT" />
31+
// <meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
3232
function updateBranchMetaData (manifest, preferences) {
3333
var metadatas = manifest['manifest']['application'][0]['meta-data'] || []
3434
var metadata = []
@@ -95,20 +95,24 @@
9595
}
9696

9797
// adds to main <activity> for URI Scheme
98-
// <intent-filter>
98+
// <intent-filter android:name="io.branch.sdk.UriScheme">
9999
// <data android:scheme="ethantest" />
100100
// <action android:name="android.intent.action.VIEW" />
101101
// <category android:name="android.intent.category.DEFAULT" />
102102
// <category android:name="android.intent.category.BROWSABLE" />
103103
// </intent-filter>
104104
function updateBranchURIScheme (manifest, mainActivityIndex, preferences) {
105105
var intentFilters = manifest['manifest']['application'][0]['activity'][mainActivityIndex]['intent-filter'] || []
106+
var androidName = 'io.branch.sdk.UriScheme'
106107

107108
// remove
108-
intentFilters = removeBasedOnIntentFilter(intentFilters)
109+
intentFilters = removeBasedOnAndroidName(intentFilters, androidName)
109110

110111
// add
111112
manifest['manifest']['application'][0]['activity'][mainActivityIndex]['intent-filter'] = intentFilters.concat([{
113+
'$': {
114+
'android:name': androidName
115+
},
112116
'action': [{
113117
'$': {
114118
'android:name': 'android.intent.action.VIEW'
@@ -134,7 +138,7 @@
134138
}
135139

136140
// adds to main <activity> for App Links (optional)
137-
// <intent-filter android:autoVerify="true">
141+
// <intent-filter android:name="io.branch.sdk.AppLink" android:autoVerify="true">
138142
// <action android:name="android.intent.action.VIEW" />
139143
// <category android:name="android.intent.category.DEFAULT" />
140144
// <category android:name="android.intent.category.BROWSABLE" />
@@ -144,10 +148,15 @@
144148
function updateBranchAppLinks (manifest, mainActivityIndex, preferences) {
145149
var intentFilters = manifest['manifest']['application'][0]['activity'][mainActivityIndex]['intent-filter'] || []
146150
var data = getAppLinkIntentFilterData(preferences)
151+
var androidName = 'io.branch.sdk.AppLink'
152+
153+
// remove
154+
intentFilters = removeBasedOnAndroidName(intentFilters, androidName)
147155

148156
// add new (remove old already done in updateBranchURIScheme)
149157
manifest['manifest']['application'][0]['activity'][mainActivityIndex]['intent-filter'] = intentFilters.concat([{
150158
'$': {
159+
'android:name': androidName,
151160
'android:autoVerify': 'true'
152161
},
153162
'action': [{
@@ -214,33 +223,6 @@
214223
return output
215224
}
216225

217-
// remove previous Branch related Intent Filters (both URI Scheme and App Link)
218-
function removeBasedOnIntentFilter (items) {
219-
var without = []
220-
for (var i = 0; i < items.length; i++) {
221-
var item = items[i]
222-
if (item.hasOwnProperty('action') && item.hasOwnProperty('category') && item.hasOwnProperty('data')) {
223-
var actions = item['action']
224-
var categories = item['category']
225-
var data = item['data']
226-
227-
if (actions.length === 1 && actions[0]['$'].hasOwnProperty('android:name') && actions[0]['$']['android:name'] === 'android.intent.action.VIEW' && categories.length === 2 && categories[0]['$'].hasOwnProperty('android:name') && (categories[0]['$']['android:name'] === 'android.intent.category.DEFAULT' || categories[0]['$']['android:name'] === 'android.intent.category.BROWSABLE') && categories[1]['$'].hasOwnProperty('android:name') && (categories[1]['$']['android:name'] === 'android.intent.category.DEFAULT' || categories[1]['$']['android:name'] === 'android.intent.category.BROWSABLE') && data.length > 0 && data.length < 3) {
228-
// URI Scheme
229-
if (data[0]['$'].hasOwnProperty('android:scheme') && !item.hasOwnProperty('$')) {
230-
continue
231-
}
232-
233-
// AppLink
234-
if (data[0]['$'].hasOwnProperty('android:host') && data[0]['$'].hasOwnProperty('android:scheme') && data[0]['$']['android:scheme'] === 'https' && item.hasOwnProperty('$') && item['$'].hasOwnProperty('android:autoVerify') && item['$']['android:autoVerify'] === 'true') {
235-
continue
236-
}
237-
}
238-
}
239-
without.push(item)
240-
}
241-
return without
242-
}
243-
244226
// remove previous Branch related <meta-data> and <receiver> based on android:name
245227
function removeBasedOnAndroidName (items, androidName) {
246228
var without = []
@@ -252,6 +234,8 @@
252234
continue
253235
}
254236
without.push(item)
237+
} else {
238+
without.push(item)
255239
}
256240
}
257241
return without
@@ -261,14 +245,13 @@
261245
function getMainLaunchActivityIndex (activities) {
262246
var launchActivityIndex = -1
263247

264-
activities.some(function (activity, index) {
248+
for (var i = 0; i < activities.length; i++) {
249+
var activity = activities[i]
265250
if (isLaunchActivity(activity)) {
266-
launchActivityIndex = index
267-
return true
251+
launchActivityIndex = i
252+
break
268253
}
269-
270-
return false
271-
})
254+
}
272255

273256
return launchActivityIndex
274257
}

0 commit comments

Comments
 (0)