|
6 | 6 | import android.content.Intent;
|
7 | 7 | import android.content.SharedPreferences;
|
8 | 8 | import android.graphics.Rect;
|
| 9 | +import android.net.Uri; |
9 | 10 | import android.os.Build;
|
10 | 11 | import android.os.Bundle;
|
11 | 12 |
|
12 | 13 | import com.google.android.gms.ads.identifier.AdvertisingIdClient;
|
13 | 14 | import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
|
14 | 15 | import com.google.android.gms.common.GooglePlayServicesRepairableException;
|
15 |
| -import com.google.firebase.iid.FirebaseInstanceId; |
| 16 | +import com.iterable.iterableapi.ddl.DeviceInfo; |
| 17 | +import com.iterable.iterableapi.ddl.MatchFpResponse; |
16 | 18 |
|
17 | 19 | import org.json.JSONArray;
|
18 | 20 | import org.json.JSONException;
|
|
23 | 25 | import java.util.Arrays;
|
24 | 26 | import java.util.Date;
|
25 | 27 | import java.util.List;
|
26 |
| -import java.util.Map; |
27 | 28 | import java.util.TimeZone;
|
28 | 29 | import java.util.UUID;
|
29 |
| -import java.util.regex.Matcher; |
30 |
| -import java.util.regex.Pattern; |
31 | 30 |
|
32 | 31 | /**
|
33 | 32 | * Created by David Truong [email protected]
|
@@ -226,6 +225,8 @@ public static void initialize(Context context, String apiKey, IterableConfig con
|
226 | 225 | }
|
227 | 226 | sharedInstance.sdkCompatEnabled = false;
|
228 | 227 | sharedInstance.retrieveEmailAndUserId();
|
| 228 | + sharedInstance.checkForDeferredDeeplink(); |
| 229 | + |
229 | 230 | if (sharedInstance.config.autoPushRegistration && sharedInstance.isInitialized()) {
|
230 | 231 | sharedInstance.registerForPush();
|
231 | 232 | }
|
@@ -1323,6 +1324,60 @@ private void onLogIn() {
|
1323 | 1324 | }
|
1324 | 1325 | }
|
1325 | 1326 |
|
| 1327 | + private boolean getDDLChecked() { |
| 1328 | + return getPreferences().getBoolean(IterableConstants.SHARED_PREFS_DDL_CHECKED_KEY, false); |
| 1329 | + } |
| 1330 | + |
| 1331 | + private void setDDLChecked(boolean value) { |
| 1332 | + getPreferences().edit().putBoolean(IterableConstants.SHARED_PREFS_DDL_CHECKED_KEY, value).apply(); |
| 1333 | + } |
| 1334 | + |
| 1335 | + private void checkForDeferredDeeplink() { |
| 1336 | + if (!config.checkForDeferredDeeplink) { |
| 1337 | + return; |
| 1338 | + } |
| 1339 | + |
| 1340 | + try { |
| 1341 | + if (getDDLChecked()) { |
| 1342 | + return; |
| 1343 | + } |
| 1344 | + |
| 1345 | + JSONObject requestJSON = DeviceInfo.createDeviceInfo(_applicationContext).toJSONObject(); |
| 1346 | + |
| 1347 | + IterableApiRequest request = new IterableApiRequest(_apiKey, IterableConstants.BASE_URL_LINKS, |
| 1348 | + IterableConstants.ENDPOINT_DDL_MATCH, requestJSON, IterableApiRequest.POST, new IterableHelper.SuccessHandler() { |
| 1349 | + @Override |
| 1350 | + public void onSuccess(JSONObject data) { |
| 1351 | + handleDDL(data); |
| 1352 | + } |
| 1353 | + }, new IterableHelper.FailureHandler() { |
| 1354 | + @Override |
| 1355 | + public void onFailure(String reason, JSONObject data) { |
| 1356 | + IterableLogger.e(TAG, "Error while checking deferred deep link: " + reason + ", response: " + data); |
| 1357 | + } |
| 1358 | + }); |
| 1359 | + new IterableRequest().execute(request); |
| 1360 | + |
| 1361 | + } catch (Exception e) { |
| 1362 | + IterableLogger.e(TAG, "Error while checking deferred deep link", e); |
| 1363 | + } |
| 1364 | + } |
| 1365 | + |
| 1366 | + private void handleDDL(JSONObject response) { |
| 1367 | + IterableLogger.d(TAG, "handleDDL: " + response); |
| 1368 | + try { |
| 1369 | + MatchFpResponse matchFpResponse = MatchFpResponse.fromJSONObject(response); |
| 1370 | + |
| 1371 | + if (matchFpResponse.isMatch) { |
| 1372 | + IterableAction action = IterableAction.actionOpenUrl(matchFpResponse.destinationUrl); |
| 1373 | + IterableActionRunner.executeAction(getMainActivityContext(), action, IterableActionSource.APP_LINK); |
| 1374 | + } |
| 1375 | + } catch (JSONException e) { |
| 1376 | + IterableLogger.e(TAG, "Error while handling deferred deep link", e); |
| 1377 | + } |
| 1378 | + setDDLChecked(true); |
| 1379 | + } |
| 1380 | + |
1326 | 1381 | //---------------------------------------------------------------------------------------
|
1327 | 1382 | //endregion
|
1328 | 1383 |
|
|
0 commit comments