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 ;
9+ import android .util .Log ;
1010
1111import com .google .android .gms .ads .identifier .AdvertisingIdClient ;
1212import com .google .android .gms .common .GooglePlayServicesNotAvailableException ;
1313import 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 ;
1417
1518import org .json .JSONException ;
1619import org .json .JSONObject ;
1720
1821import java .io .IOException ;
1922import java .text .SimpleDateFormat ;
2023import java .util .Date ;
24+ import java .util .Objects ;
25+ import java .util .Set ;
2126import 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 ;
2232import java .util .regex .Matcher ;
2333import java .util .regex .Pattern ;
2434
@@ -313,13 +323,17 @@ public boolean isIterableIntent(Intent intent) {
313323 }
314324
315325 /**
316- * Registers an existing GCM device token with Iterable.
326+ * Registers an existing device token with Iterable.
317327 * Recommended to use registerForPush if you do not already have a deviceToken
318328 * @param applicationName
319329 * @param token
320330 */
321- public void registerDeviceToken (String applicationName , String token ) {
322- registerDeviceToken (applicationName , token , null );
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 ();
323337 }
324338
325339 /**
@@ -470,20 +484,45 @@ 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.
504+ * The disablePush call
481505 *
482506 * @param iterableAppId
483507 * @param gcmProjectNumber
484508 */
485509 public void disablePush (String iterableAppId , String gcmProjectNumber ) {
486- registerForPush (iterableAppId , gcmProjectNumber , true );
510+ disablePush (iterableAppId , gcmProjectNumber , IterableConstants .MESSAGING_PLATFORM_GOOGLE );
511+ }
512+
513+ /**
514+ * Disables the device from push notifications
515+ *
516+ * The disablePush call
517+ *
518+ * @param iterableAppId
519+ * @param projectNumber
520+ * @param pushServicePlatform
521+ */
522+ public void disablePush (String iterableAppId , String projectNumber , String pushServicePlatform ) {
523+
524+ IterablePushRegistrationData data = new IterablePushRegistrationData (iterableAppId , projectNumber , pushServicePlatform , IterablePushRegistrationData .PushRegistrationAction .DISABLE );
525+ new IterablePushRegistration ().execute (data );
487526 }
488527
489528 /**
@@ -606,21 +645,6 @@ static String getNotificationIcon(Context context) {
606645 return iconName ;
607646 }
608647
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-
624648 /**
625649 * Tracks when a push notification is opened on device.
626650 * @param campaignId
@@ -643,7 +667,7 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
643667 }
644668
645669 /**
646- * Internal api call made from IterablePushRegistrationGCM after a registrationToken is obtained.
670+ * Internal api call made from IterablePushRegistration after a registrationToken is obtained.
647671 * @param token
648672 */
649673 protected void disablePush (String token ) {
0 commit comments