6
6
import android .content .SharedPreferences ;
7
7
import android .os .Build ;
8
8
import android .os .Bundle ;
9
- import android .util .Log ;
10
9
11
10
import com .google .android .gms .ads .identifier .AdvertisingIdClient ;
12
11
import com .google .android .gms .common .GooglePlayServicesNotAvailableException ;
13
12
import com .google .android .gms .common .GooglePlayServicesRepairableException ;
14
- import com .google .android .gms .gcm .GoogleCloudMessaging ;
15
- import com .google .android .gms .iid .InstanceID ;
16
- import com .google .firebase .iid .FirebaseInstanceId ;
17
13
18
14
import org .json .JSONException ;
19
15
import org .json .JSONObject ;
20
16
21
17
import java .io .IOException ;
22
18
import java .text .SimpleDateFormat ;
23
19
import java .util .Date ;
24
- import java .util .Objects ;
25
- import java .util .Set ;
26
20
import java .util .TimeZone ;
27
- import java .util .concurrent .Callable ;
28
- import java .util .concurrent .ExecutionException ;
29
- import java .util .concurrent .ExecutorService ;
30
- import java .util .concurrent .Executors ;
31
- import java .util .concurrent .Future ;
32
21
import java .util .regex .Matcher ;
33
22
import java .util .regex .Pattern ;
34
23
@@ -323,17 +312,28 @@ public boolean isIterableIntent(Intent intent) {
323
312
}
324
313
325
314
/**
326
- * Registers an existing device token with Iterable.
327
- * Recommended to use registerForPush if you do not already have a deviceToken
315
+ * Registers a device token with Iterable.
328
316
* @param applicationName
329
317
* @param token
330
318
*/
331
- public void registerDeviceToken (final String applicationName , final String token ) {
332
- new Thread (new Runnable () {
333
- public void run () {
334
- registerDeviceToken (applicationName , token , null );
335
- }
336
- }).start ();
319
+ public void registerDeviceToken (String applicationName , String token ) {
320
+ registerDeviceToken (applicationName , token , null );
321
+ }
322
+
323
+ /**
324
+ * Registers a device token with Iterable.
325
+ * @param applicationName
326
+ * @param token
327
+ * @param pushServicePlatform
328
+ */
329
+ public void registerDeviceToken (final String applicationName , final String token , final String pushServicePlatform ) {
330
+ if (token != null ) {
331
+ new Thread (new Runnable () {
332
+ public void run () {
333
+ registerDeviceToken (applicationName , token , pushServicePlatform , null );
334
+ }
335
+ }).start ();
336
+ }
337
337
}
338
338
339
339
/**
@@ -501,8 +501,6 @@ public void registerForPush(String iterableAppId, String projectNumber, String p
501
501
/**
502
502
* Disables the device from push notifications
503
503
*
504
- * The disablePush call
505
- *
506
504
* @param iterableAppId
507
505
* @param gcmProjectNumber
508
506
*/
@@ -513,14 +511,11 @@ public void disablePush(String iterableAppId, String gcmProjectNumber) {
513
511
/**
514
512
* Disables the device from push notifications
515
513
*
516
- * The disablePush call
517
- *
518
514
* @param iterableAppId
519
515
* @param projectNumber
520
516
* @param pushServicePlatform
521
517
*/
522
518
public void disablePush (String iterableAppId , String projectNumber , String pushServicePlatform ) {
523
-
524
519
IterablePushRegistrationData data = new IterablePushRegistrationData (iterableAppId , projectNumber , pushServicePlatform , IterablePushRegistrationData .PushRegistrationAction .DISABLE );
525
520
new IterablePushRegistration ().execute (data );
526
521
}
@@ -601,7 +596,7 @@ public void trackInAppClick(String messageId, int buttonIndex) {
601
596
JSONObject requestJSON = new JSONObject ();
602
597
603
598
try {
604
- requestJSON . put ( IterableConstants . KEY_EMAIL , _email );
599
+ addEmailOrUserIdToJson ( requestJSON );
605
600
requestJSON .put (IterableConstants .KEY_MESSAGE_ID , messageId );
606
601
requestJSON .put (IterableConstants .ITERABLE_IN_APP_BUTTON_INDEX , buttonIndex );
607
602
}
@@ -696,6 +691,48 @@ protected void disablePush(String token) {
696
691
sendPostRequest (IterableConstants .ENDPOINT_DISABLE_DEVICE , requestJSON );
697
692
}
698
693
694
+ /**
695
+ * Registers the GCM registration ID with Iterable.
696
+ * @param applicationName
697
+ * @param token
698
+ * @param pushServicePlatform
699
+ * @param dataFields
700
+ */
701
+ protected void registerDeviceToken (String applicationName , String token , String pushServicePlatform , JSONObject dataFields ) {
702
+ String platform = IterableConstants .MESSAGING_PLATFORM_GOOGLE ;
703
+
704
+ JSONObject requestJSON = new JSONObject ();
705
+ try {
706
+ addEmailOrUserIdToJson (requestJSON );
707
+
708
+ if (dataFields == null ) {
709
+ dataFields = new JSONObject ();
710
+ }
711
+ if (pushServicePlatform != null ) {
712
+ dataFields .put (IterableConstants .FIREBASE_COMPATIBLE , pushServicePlatform .equalsIgnoreCase (IterableConstants .MESSAGING_PLATFORM_FIREBASE ));
713
+ }
714
+ dataFields .put (IterableConstants .DEVICE_BRAND , Build .BRAND ); //brand: google
715
+ dataFields .put (IterableConstants .DEVICE_MANUFACTURER , Build .MANUFACTURER ); //manufacturer: samsung
716
+ dataFields .putOpt (IterableConstants .DEVICE_ADID , getAdvertisingId ()); //ADID: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
717
+ dataFields .put (IterableConstants .DEVICE_SYSTEM_NAME , Build .DEVICE ); //device name: toro
718
+ dataFields .put (IterableConstants .DEVICE_SYSTEM_VERSION , Build .VERSION .RELEASE ); //version: 4.0.4
719
+ dataFields .put (IterableConstants .DEVICE_MODEL , Build .MODEL ); //device model: Galaxy Nexus
720
+ dataFields .put (IterableConstants .DEVICE_SDK_VERSION , Build .VERSION .SDK_INT ); //sdk version/api level: 15
721
+
722
+ JSONObject device = new JSONObject ();
723
+ device .put (IterableConstants .KEY_TOKEN , token );
724
+ device .put (IterableConstants .KEY_PLATFORM , platform );
725
+ device .put (IterableConstants .KEY_APPLICATION_NAME , applicationName );
726
+ device .putOpt (IterableConstants .KEY_DATA_FIELDS , dataFields );
727
+ requestJSON .put (IterableConstants .KEY_DEVICE , device );
728
+
729
+ } catch (JSONException e ) {
730
+ e .printStackTrace ();
731
+ }
732
+
733
+ sendPostRequest (IterableConstants .ENDPOINT_REGISTER_DEVICE_TOKEN , requestJSON );
734
+ }
735
+
699
736
//---------------------------------------------------------------------------------------
700
737
//endregion
701
738
@@ -732,44 +769,6 @@ private void tryTrackNotifOpen(Intent calledIntent) {
732
769
}
733
770
}
734
771
735
- /**
736
- * Registers the GCM registration ID with Iterable.
737
- * @param applicationName
738
- * @param token
739
- * @param dataFields
740
- */
741
- private void registerDeviceToken (String applicationName , String token , JSONObject dataFields ) {
742
- String platform = IterableConstants .MESSAGING_PLATFORM_GOOGLE ;
743
-
744
- JSONObject requestJSON = new JSONObject ();
745
- try {
746
- addEmailOrUserIdToJson (requestJSON );
747
-
748
- if (dataFields == null ) {
749
- dataFields = new JSONObject ();
750
- dataFields .put ("brand" , Build .BRAND ); //brand: google
751
- dataFields .put ("manufacturer" , Build .MANUFACTURER ); //manufacturer: samsung
752
- dataFields .putOpt ("advertisingId" , getAdvertisingId ()); //ADID: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
753
- dataFields .put ("systemName" , Build .DEVICE ); //device name: toro
754
- dataFields .put ("systemVersion" , Build .VERSION .RELEASE ); //version: 4.0.4
755
- dataFields .put ("model" , Build .MODEL ); //device model: Galaxy Nexus
756
- dataFields .put ("sdkVersion" , Build .VERSION .SDK_INT ); //sdk version/api level: 15
757
- }
758
-
759
- JSONObject device = new JSONObject ();
760
- device .put (IterableConstants .KEY_TOKEN , token );
761
- device .put (IterableConstants .KEY_PLATFORM , platform );
762
- device .put (IterableConstants .KEY_APPLICATION_NAME , applicationName );
763
- device .putOpt (IterableConstants .KEY_DATA_FIELDS , dataFields );
764
- requestJSON .put (IterableConstants .KEY_DEVICE , device );
765
-
766
- } catch (JSONException e ) {
767
- e .printStackTrace ();
768
- }
769
-
770
- sendPostRequest (IterableConstants .ENDPOINT_REGISTER_DEVICE_TOKEN , requestJSON );
771
- }
772
-
773
772
/**
774
773
* Sends the POST request to Iterable.
775
774
* Performs network operations on an async thread instead of the main thread.
0 commit comments