4
4
import android .content .Context ;
5
5
import android .content .Intent ;
6
6
import android .content .SharedPreferences ;
7
- import android .net .Uri ;
8
7
import android .os .Build ;
9
8
import android .os .Bundle ;
10
9
@@ -313,15 +312,30 @@ public boolean isIterableIntent(Intent intent) {
313
312
}
314
313
315
314
/**
316
- * Registers an existing GCM device token with Iterable.
317
- * Recommended to use registerForPush if you do not already have a deviceToken
315
+ * Registers a device token with Iterable.
318
316
* @param applicationName
319
317
* @param token
320
318
*/
321
319
public void registerDeviceToken (String applicationName , String token ) {
322
320
registerDeviceToken (applicationName , token , null );
323
321
}
324
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
+ }
338
+
325
339
/**
326
340
* Track an event.
327
341
* @param eventName
@@ -470,20 +484,40 @@ public void updateUser(JSONObject dataFields) {
470
484
* @param gcmProjectNumber
471
485
*/
472
486
public void registerForPush (String iterableAppId , String gcmProjectNumber ) {
473
- registerForPush (iterableAppId , gcmProjectNumber , false );
487
+ registerForPush (iterableAppId , gcmProjectNumber , IterableConstants .MESSAGING_PLATFORM_GOOGLE );
488
+ }
489
+
490
+ /**
491
+ * Registers for push notifications.
492
+ * @param iterableAppId
493
+ * @param projectNumber
494
+ * @param pushServicePlatform
495
+ */
496
+ public void registerForPush (String iterableAppId , String projectNumber , String pushServicePlatform ) {
497
+ IterablePushRegistrationData data = new IterablePushRegistrationData (iterableAppId , projectNumber , pushServicePlatform , IterablePushRegistrationData .PushRegistrationAction .ENABLE );
498
+ new IterablePushRegistration ().execute (data );
474
499
}
475
500
476
501
/**
477
502
* Disables the device from push notifications
478
503
*
479
- * The disablePush call first calls registerForPush to obtain the device's registration token.
480
- * Then it calls the disablePush api endpoint.
481
- *
482
504
* @param iterableAppId
483
505
* @param gcmProjectNumber
484
506
*/
485
507
public void disablePush (String iterableAppId , String gcmProjectNumber ) {
486
- registerForPush (iterableAppId , gcmProjectNumber , true );
508
+ disablePush (iterableAppId , gcmProjectNumber , IterableConstants .MESSAGING_PLATFORM_GOOGLE );
509
+ }
510
+
511
+ /**
512
+ * Disables the device from push notifications
513
+ *
514
+ * @param iterableAppId
515
+ * @param projectNumber
516
+ * @param pushServicePlatform
517
+ */
518
+ public void disablePush (String iterableAppId , String projectNumber , String pushServicePlatform ) {
519
+ IterablePushRegistrationData data = new IterablePushRegistrationData (iterableAppId , projectNumber , pushServicePlatform , IterablePushRegistrationData .PushRegistrationAction .DISABLE );
520
+ new IterablePushRegistration ().execute (data );
487
521
}
488
522
489
523
/**
@@ -606,21 +640,6 @@ static String getNotificationIcon(Context context) {
606
640
return iconName ;
607
641
}
608
642
609
- /**
610
- * Registers the device for push notifications.
611
- * @param iterableAppId
612
- * @param gcmProjectNumber
613
- * @param disableAfterRegistration
614
- */
615
- protected void registerForPush (String iterableAppId , String gcmProjectNumber , boolean disableAfterRegistration ) {
616
- Intent pushRegistrationIntent = new Intent (_applicationContext , IterablePushReceiver .class );
617
- pushRegistrationIntent .setAction (IterableConstants .ACTION_PUSH_REGISTRATION );
618
- pushRegistrationIntent .putExtra (IterableConstants .PUSH_APP_ID , iterableAppId );
619
- pushRegistrationIntent .putExtra (IterableConstants .PUSH_GCM_PROJECT_NUMBER , gcmProjectNumber );
620
- pushRegistrationIntent .putExtra (IterableConstants .PUSH_DISABLE_AFTER_REGISTRATION , disableAfterRegistration );
621
- _applicationContext .sendBroadcast (pushRegistrationIntent );
622
- }
623
-
624
643
/**
625
644
* Tracks when a push notification is opened on device.
626
645
* @param campaignId
@@ -643,7 +662,7 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
643
662
}
644
663
645
664
/**
646
- * Internal api call made from IterablePushRegistrationGCM after a registrationToken is obtained.
665
+ * Internal api call made from IterablePushRegistration after a registrationToken is obtained.
647
666
* @param token
648
667
*/
649
668
protected void disablePush (String token ) {
@@ -658,6 +677,48 @@ protected void disablePush(String token) {
658
677
sendPostRequest (IterableConstants .ENDPOINT_DISABLE_DEVICE , requestJSON );
659
678
}
660
679
680
+ /**
681
+ * Registers the GCM registration ID with Iterable.
682
+ * @param applicationName
683
+ * @param token
684
+ * @param pushServicePlatform
685
+ * @param dataFields
686
+ */
687
+ protected void registerDeviceToken (String applicationName , String token , String pushServicePlatform , JSONObject dataFields ) {
688
+ String platform = IterableConstants .MESSAGING_PLATFORM_GOOGLE ;
689
+
690
+ JSONObject requestJSON = new JSONObject ();
691
+ try {
692
+ addEmailOrUserIdToJson (requestJSON );
693
+
694
+ if (dataFields == null ) {
695
+ dataFields = new JSONObject ();
696
+ }
697
+ if (pushServicePlatform != null ) {
698
+ dataFields .put (IterableConstants .FIREBASE_COMPATIBLE , pushServicePlatform .equalsIgnoreCase (IterableConstants .MESSAGING_PLATFORM_FIREBASE ));
699
+ }
700
+ dataFields .put (IterableConstants .DEVICE_BRAND , Build .BRAND ); //brand: google
701
+ dataFields .put (IterableConstants .DEVICE_MANUFACTURER , Build .MANUFACTURER ); //manufacturer: samsung
702
+ dataFields .putOpt (IterableConstants .DEVICE_ADID , getAdvertisingId ()); //ADID: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
703
+ dataFields .put (IterableConstants .DEVICE_SYSTEM_NAME , Build .DEVICE ); //device name: toro
704
+ dataFields .put (IterableConstants .DEVICE_SYSTEM_VERSION , Build .VERSION .RELEASE ); //version: 4.0.4
705
+ dataFields .put (IterableConstants .DEVICE_MODEL , Build .MODEL ); //device model: Galaxy Nexus
706
+ dataFields .put (IterableConstants .DEVICE_SDK_VERSION , Build .VERSION .SDK_INT ); //sdk version/api level: 15
707
+
708
+ JSONObject device = new JSONObject ();
709
+ device .put (IterableConstants .KEY_TOKEN , token );
710
+ device .put (IterableConstants .KEY_PLATFORM , platform );
711
+ device .put (IterableConstants .KEY_APPLICATION_NAME , applicationName );
712
+ device .putOpt (IterableConstants .KEY_DATA_FIELDS , dataFields );
713
+ requestJSON .put (IterableConstants .KEY_DEVICE , device );
714
+
715
+ } catch (JSONException e ) {
716
+ e .printStackTrace ();
717
+ }
718
+
719
+ sendPostRequest (IterableConstants .ENDPOINT_REGISTER_DEVICE_TOKEN , requestJSON );
720
+ }
721
+
661
722
//---------------------------------------------------------------------------------------
662
723
//endregion
663
724
@@ -694,44 +755,6 @@ private void tryTrackNotifOpen(Intent calledIntent) {
694
755
}
695
756
}
696
757
697
- /**
698
- * Registers the GCM registration ID with Iterable.
699
- * @param applicationName
700
- * @param token
701
- * @param dataFields
702
- */
703
- private void registerDeviceToken (String applicationName , String token , JSONObject dataFields ) {
704
- String platform = IterableConstants .MESSAGING_PLATFORM_GOOGLE ;
705
-
706
- JSONObject requestJSON = new JSONObject ();
707
- try {
708
- addEmailOrUserIdToJson (requestJSON );
709
-
710
- if (dataFields == null ) {
711
- dataFields = new JSONObject ();
712
- dataFields .put ("brand" , Build .BRAND ); //brand: google
713
- dataFields .put ("manufacturer" , Build .MANUFACTURER ); //manufacturer: samsung
714
- dataFields .putOpt ("advertisingId" , getAdvertisingId ()); //ADID: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
715
- dataFields .put ("systemName" , Build .DEVICE ); //device name: toro
716
- dataFields .put ("systemVersion" , Build .VERSION .RELEASE ); //version: 4.0.4
717
- dataFields .put ("model" , Build .MODEL ); //device model: Galaxy Nexus
718
- dataFields .put ("sdkVersion" , Build .VERSION .SDK_INT ); //sdk version/api level: 15
719
- }
720
-
721
- JSONObject device = new JSONObject ();
722
- device .put (IterableConstants .KEY_TOKEN , token );
723
- device .put (IterableConstants .KEY_PLATFORM , platform );
724
- device .put (IterableConstants .KEY_APPLICATION_NAME , applicationName );
725
- device .putOpt (IterableConstants .KEY_DATA_FIELDS , dataFields );
726
- requestJSON .put (IterableConstants .KEY_DEVICE , device );
727
-
728
- } catch (JSONException e ) {
729
- e .printStackTrace ();
730
- }
731
-
732
- sendPostRequest (IterableConstants .ENDPOINT_REGISTER_DEVICE_TOKEN , requestJSON );
733
- }
734
-
735
758
/**
736
759
* Sends the POST request to Iterable.
737
760
* Performs network operations on an async thread instead of the main thread.
0 commit comments