|
27 | 27 | }
|
28 | 28 |
|
29 | 29 | // 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" /> |
32 | 32 | function updateBranchMetaData (manifest, preferences) {
|
33 | 33 | var metadatas = manifest['manifest']['application'][0]['meta-data'] || []
|
34 | 34 | var metadata = []
|
|
95 | 95 | }
|
96 | 96 |
|
97 | 97 | // adds to main <activity> for URI Scheme
|
98 |
| - // <intent-filter> |
| 98 | + // <intent-filter android:name="io.branch.sdk.UriScheme"> |
99 | 99 | // <data android:scheme="ethantest" />
|
100 | 100 | // <action android:name="android.intent.action.VIEW" />
|
101 | 101 | // <category android:name="android.intent.category.DEFAULT" />
|
102 | 102 | // <category android:name="android.intent.category.BROWSABLE" />
|
103 | 103 | // </intent-filter>
|
104 | 104 | function updateBranchURIScheme (manifest, mainActivityIndex, preferences) {
|
105 | 105 | var intentFilters = manifest['manifest']['application'][0]['activity'][mainActivityIndex]['intent-filter'] || []
|
| 106 | + var androidName = 'io.branch.sdk.UriScheme' |
106 | 107 |
|
107 | 108 | // remove
|
108 |
| - intentFilters = removeBasedOnIntentFilter(intentFilters) |
| 109 | + intentFilters = removeBasedOnAndroidName(intentFilters, androidName) |
109 | 110 |
|
110 | 111 | // add
|
111 | 112 | manifest['manifest']['application'][0]['activity'][mainActivityIndex]['intent-filter'] = intentFilters.concat([{
|
| 113 | + '$': { |
| 114 | + 'android:name': androidName |
| 115 | + }, |
112 | 116 | 'action': [{
|
113 | 117 | '$': {
|
114 | 118 | 'android:name': 'android.intent.action.VIEW'
|
|
134 | 138 | }
|
135 | 139 |
|
136 | 140 | // 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"> |
138 | 142 | // <action android:name="android.intent.action.VIEW" />
|
139 | 143 | // <category android:name="android.intent.category.DEFAULT" />
|
140 | 144 | // <category android:name="android.intent.category.BROWSABLE" />
|
|
144 | 148 | function updateBranchAppLinks (manifest, mainActivityIndex, preferences) {
|
145 | 149 | var intentFilters = manifest['manifest']['application'][0]['activity'][mainActivityIndex]['intent-filter'] || []
|
146 | 150 | var data = getAppLinkIntentFilterData(preferences)
|
| 151 | + var androidName = 'io.branch.sdk.AppLink' |
| 152 | + |
| 153 | + // remove |
| 154 | + intentFilters = removeBasedOnAndroidName(intentFilters, androidName) |
147 | 155 |
|
148 | 156 | // add new (remove old already done in updateBranchURIScheme)
|
149 | 157 | manifest['manifest']['application'][0]['activity'][mainActivityIndex]['intent-filter'] = intentFilters.concat([{
|
150 | 158 | '$': {
|
| 159 | + 'android:name': androidName, |
151 | 160 | 'android:autoVerify': 'true'
|
152 | 161 | },
|
153 | 162 | 'action': [{
|
|
214 | 223 | return output
|
215 | 224 | }
|
216 | 225 |
|
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 |
| - |
244 | 226 | // remove previous Branch related <meta-data> and <receiver> based on android:name
|
245 | 227 | function removeBasedOnAndroidName (items, androidName) {
|
246 | 228 | var without = []
|
|
252 | 234 | continue
|
253 | 235 | }
|
254 | 236 | without.push(item)
|
| 237 | + } else { |
| 238 | + without.push(item) |
255 | 239 | }
|
256 | 240 | }
|
257 | 241 | return without
|
|
261 | 245 | function getMainLaunchActivityIndex (activities) {
|
262 | 246 | var launchActivityIndex = -1
|
263 | 247 |
|
264 |
| - activities.some(function (activity, index) { |
| 248 | + for (var i = 0; i < activities.length; i++) { |
| 249 | + var activity = activities[i] |
265 | 250 | if (isLaunchActivity(activity)) {
|
266 |
| - launchActivityIndex = index |
267 |
| - return true |
| 251 | + launchActivityIndex = i |
| 252 | + break |
268 | 253 | }
|
269 |
| - |
270 |
| - return false |
271 |
| - }) |
| 254 | + } |
272 | 255 |
|
273 | 256 | return launchActivityIndex
|
274 | 257 | }
|
|
0 commit comments