44import android .content .Context ;
55import android .content .Intent ;
66import android .content .SharedPreferences ;
7- import android .net .Uri ;
87import android .os .Build ;
98import android .os .Bundle ;
109
@@ -313,15 +312,30 @@ public boolean isIterableIntent(Intent intent) {
313312 }
314313
315314 /**
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.
318316 * @param applicationName
319317 * @param token
320318 */
321319 public void registerDeviceToken (String applicationName , String token ) {
322320 registerDeviceToken (applicationName , token , null );
323321 }
324322
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+
325339 /**
326340 * Track an event.
327341 * @param eventName
@@ -470,20 +484,40 @@ public void updateUser(JSONObject dataFields) {
470484 * @param gcmProjectNumber
471485 */
472486 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 );
474499 }
475500
476501 /**
477502 * Disables the device from push notifications
478503 *
479- * The disablePush call first calls registerForPush to obtain the device's registration token.
480- * Then it calls the disablePush api endpoint.
481- *
482504 * @param iterableAppId
483505 * @param gcmProjectNumber
484506 */
485507 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 );
487521 }
488522
489523 /**
@@ -606,21 +640,6 @@ static String getNotificationIcon(Context context) {
606640 return iconName ;
607641 }
608642
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-
624643 /**
625644 * Tracks when a push notification is opened on device.
626645 * @param campaignId
@@ -643,7 +662,7 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
643662 }
644663
645664 /**
646- * Internal api call made from IterablePushRegistrationGCM after a registrationToken is obtained.
665+ * Internal api call made from IterablePushRegistration after a registrationToken is obtained.
647666 * @param token
648667 */
649668 protected void disablePush (String token ) {
@@ -658,6 +677,48 @@ protected void disablePush(String token) {
658677 sendPostRequest (IterableConstants .ENDPOINT_DISABLE_DEVICE , requestJSON );
659678 }
660679
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+
661722//---------------------------------------------------------------------------------------
662723//endregion
663724
@@ -694,44 +755,6 @@ private void tryTrackNotifOpen(Intent calledIntent) {
694755 }
695756 }
696757
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-
735758 /**
736759 * Sends the POST request to Iterable.
737760 * Performs network operations on an async thread instead of the main thread.
0 commit comments