66import android .content .SharedPreferences ;
77import android .os .Build ;
88import android .os .Bundle ;
9- import android .util .Log ;
109
1110import com .google .android .gms .ads .identifier .AdvertisingIdClient ;
1211import com .google .android .gms .common .GooglePlayServicesNotAvailableException ;
1312import 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 ;
1713
1814import org .json .JSONException ;
1915import org .json .JSONObject ;
2016
2117import java .io .IOException ;
2218import java .text .SimpleDateFormat ;
2319import java .util .Date ;
24- import java .util .Objects ;
25- import java .util .Set ;
2620import 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 ;
3221import java .util .regex .Matcher ;
3322import java .util .regex .Pattern ;
3423
@@ -323,17 +312,28 @@ public boolean isIterableIntent(Intent intent) {
323312 }
324313
325314 /**
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.
328316 * @param applicationName
329317 * @param token
330318 */
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+ }
337337 }
338338
339339 /**
@@ -501,8 +501,6 @@ public void registerForPush(String iterableAppId, String projectNumber, String p
501501 /**
502502 * Disables the device from push notifications
503503 *
504- * The disablePush call
505- *
506504 * @param iterableAppId
507505 * @param gcmProjectNumber
508506 */
@@ -513,14 +511,11 @@ public void disablePush(String iterableAppId, String gcmProjectNumber) {
513511 /**
514512 * Disables the device from push notifications
515513 *
516- * The disablePush call
517- *
518514 * @param iterableAppId
519515 * @param projectNumber
520516 * @param pushServicePlatform
521517 */
522518 public void disablePush (String iterableAppId , String projectNumber , String pushServicePlatform ) {
523-
524519 IterablePushRegistrationData data = new IterablePushRegistrationData (iterableAppId , projectNumber , pushServicePlatform , IterablePushRegistrationData .PushRegistrationAction .DISABLE );
525520 new IterablePushRegistration ().execute (data );
526521 }
@@ -601,7 +596,7 @@ public void trackInAppClick(String messageId, int buttonIndex) {
601596 JSONObject requestJSON = new JSONObject ();
602597
603598 try {
604- requestJSON . put ( IterableConstants . KEY_EMAIL , _email );
599+ addEmailOrUserIdToJson ( requestJSON );
605600 requestJSON .put (IterableConstants .KEY_MESSAGE_ID , messageId );
606601 requestJSON .put (IterableConstants .ITERABLE_IN_APP_BUTTON_INDEX , buttonIndex );
607602 }
@@ -696,6 +691,48 @@ protected void disablePush(String token) {
696691 sendPostRequest (IterableConstants .ENDPOINT_DISABLE_DEVICE , requestJSON );
697692 }
698693
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+
699736//---------------------------------------------------------------------------------------
700737//endregion
701738
@@ -732,44 +769,6 @@ private void tryTrackNotifOpen(Intent calledIntent) {
732769 }
733770 }
734771
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-
773772 /**
774773 * Sends the POST request to Iterable.
775774 * Performs network operations on an async thread instead of the main thread.
0 commit comments