Skip to content

Commit e8af255

Browse files
authored
Merge branch 'master' into feature/ITBL-2397-in-app-consume
2 parents 9249b8f + bb58cb5 commit e8af255

File tree

11 files changed

+248
-181
lines changed

11 files changed

+248
-181
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1515
#### Fixed
1616
- nothing yet
1717

18+
## [2.1.5](https://github.com/Iterable/iterable-android-sdk/releases/tag/2.1.5)
19+
_Released on 2017-06-09_
20+
21+
#### Added
22+
- Added full support for newly created Firebase applications
23+
- Added new functionality for `registerForPush` which takes in the optional pushServicePlatform
24+
- `IterableConstants.MESSAGING_PLATFORM_GOOGLE` (GCM)
25+
- `IterableConstants. MESSAGING_PLATFORM_FIREBASE` (FCM)
26+
- `IterableFirebaseInstanceIDService` handles firebase token registrations automatically on install.
27+
- Added in default tracked device values for `registerDeviceToken`
28+
29+
#### Changed
30+
- Changed IterablePushRegistrationGCM to IterablePushRegistration so the registration class is not GCM specific.
31+
- Changed the disable logic to no longer enable the deviceToken prior to disabling.
32+
1833
## [2.1.4](https://github.com/Iterable/iterable-android-sdk/releases/tag/2.1.4)
1934
_Released on 2017-02-23_
2035

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ protected void onCreate(Bundle savedInstanceState) {
5858
}
5959
```
6060

61+
# Firebase Messaging
62+
At this time there is no requirement to upgrade to FCM since Google will continue to support current versions of GCM android.
63+
64+
If you want to use using Firebase Cloud Messaging (FCM) instead of Google Cloud Messaging (GCM) pass in `IterableConstants. MESSAGING_PLATFORM_FIREBASE` as the pushServicePlatform.
65+
66+
```java
67+
public void registerForPush(String iterableAppId, String projectNumber, String pushServicePlatform) {
68+
```
69+
70+
**Note**: If you are upgrading to FCM, do not downgrade back to GCM as this will cause devices to be registered for notifications twice and users will get duplicate notifications.
71+
6172
# License
6273

6374
The MIT License

iterableapi/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ext {
4141
siteUrl = 'https://github.com/Iterable/iterable-android-sdk'
4242
gitUrl = 'https://github.com/Iterable/iterable-android-sdk.git'
4343

44-
libraryVersion = '2.1.4'
44+
libraryVersion = '2.1.5'
4545

4646
developerId = 'davidtruong'
4747
developerName = 'David Truong'
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.iterable.iterableapi;
2+
3+
import android.app.Application;
4+
import android.content.Context;
5+
import android.content.SharedPreferences;
6+
import android.test.ApplicationTestCase;
7+
8+
/**
9+
* Tests
10+
* Created by David Truong [email protected].
11+
*/
12+
public class IterablePushRegistrationTest extends ApplicationTestCase<Application> {
13+
public IterablePushRegistrationTest() {
14+
super(Application.class);
15+
}
16+
17+
Context appContext;
18+
IterableApi iterableApi;
19+
String senderID = "111111111111";
20+
21+
public void setUp() throws Exception {
22+
super.setUp();
23+
24+
appContext = getContext().getApplicationContext();
25+
iterableApi = IterableApi.sharedInstanceWithApiKey(appContext, "fake_key", "test_email");
26+
27+
SharedPreferences sharedPref = appContext.getSharedPreferences(IterableConstants.PUSH_APP_ID, Context.MODE_PRIVATE);
28+
SharedPreferences.Editor editor = sharedPref.edit();
29+
editor.remove(IterableConstants.PUSH_APP_ID);
30+
editor.commit();
31+
}
32+
33+
/**
34+
* Tests getting a token for GCM
35+
* @throws Exception
36+
*/
37+
public void testGetGCMToken() throws Exception {
38+
IterablePushRegistration registration = new IterablePushRegistration();
39+
IterablePushRegistration.PushRegistrationObject registrationObject = registration.getDeviceToken(senderID, IterableConstants.MESSAGING_PLATFORM_GOOGLE, "test_application_GCM", false);
40+
assertNotNull(registrationObject.token);
41+
assertEquals(IterableConstants.MESSAGING_PLATFORM_GOOGLE, registrationObject.messagingPlatform);
42+
43+
SharedPreferences sharedPref = appContext.getSharedPreferences(IterableConstants.PUSH_APP_ID, Context.MODE_PRIVATE);
44+
String pushIdPref = sharedPref.getString(IterableConstants.PUSH_APP_ID, null);
45+
assertNull(pushIdPref);
46+
}
47+
48+
/**
49+
* Tests getting a token for FCM. Defaults to GCM if the project hasn't upgraded to Firebase and included the google-services.json
50+
* Checks the sharedPref flag that is set after upgrading to firebase.
51+
* @throws Exception
52+
*/
53+
public void testGetFCMToken() throws Exception {
54+
IterablePushRegistration registration = new IterablePushRegistration();
55+
SharedPreferences sharedPref;
56+
String pushIdPref;
57+
IterablePushRegistration.PushRegistrationObject registrationObject = registration.getDeviceToken(senderID, IterableConstants.MESSAGING_PLATFORM_FIREBASE, "test_application_FCM", false);
58+
assertNotNull(registrationObject.token);
59+
if (IterablePushRegistration.getFirebaseResouceId(appContext) != 0) {
60+
//FCM registration
61+
sharedPref = appContext.getSharedPreferences(IterableConstants.PUSH_APP_ID, Context.MODE_PRIVATE);
62+
pushIdPref = sharedPref.getString(IterableConstants.PUSH_APP_ID, null);
63+
assertNotNull(pushIdPref);
64+
assertEquals(IterableConstants.MESSAGING_PLATFORM_FIREBASE, registrationObject.messagingPlatform);
65+
66+
} else {
67+
//GCM registration
68+
sharedPref = appContext.getSharedPreferences(IterableConstants.PUSH_APP_ID, Context.MODE_PRIVATE);
69+
pushIdPref = sharedPref.getString(IterableConstants.PUSH_APP_ID, null);
70+
assertNull(pushIdPref);
71+
assertEquals(IterableConstants.MESSAGING_PLATFORM_GOOGLE, registrationObject.messagingPlatform);
72+
}
73+
}
74+
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,18 @@
66
import android.content.SharedPreferences;
77
import android.os.Build;
88
import android.os.Bundle;
9-
import android.util.Log;
109

1110
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
1211
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
1312
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;
1713

1814
import org.json.JSONException;
1915
import org.json.JSONObject;
2016

2117
import java.io.IOException;
2218
import java.text.SimpleDateFormat;
2319
import java.util.Date;
24-
import java.util.Objects;
25-
import java.util.Set;
2620
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;
3221
import java.util.regex.Matcher;
3322
import 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.

iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public final class IterableConstants {
4848
public static final String PUSH_GCM_PROJECT_NUMBER = "GCMProjectNumber";
4949
public static final String PUSH_DISABLE_AFTER_REGISTRATION = "DisableAfterRegistration";
5050

51-
public static final String MESSAGING_PUSH_SERVICE_PLATFORM = "PushServicePlatform";
51+
public static final String MESSAGING_PUSH_SERVICE_PLATFORM = "PushServicePlatform";
5252
public static final String MESSAGING_PLATFORM_GOOGLE = "GCM";
5353
public static final String MESSAGING_PLATFORM_FIREBASE = "FCM";
5454
public static final String MESSAGING_PLATFORM_AMAZON = "ADM";
@@ -59,14 +59,30 @@ public final class IterableConstants {
5959
public static final String ITERABLE_DATA_TITLE = "title";
6060
public static final String ITERABLE_DATA_SOUND = "sound";
6161

62+
//Device
63+
public static final String DEVICE_BRAND = "brand";
64+
public static final String DEVICE_MANUFACTURER = "manufacturer";
65+
public static final String DEVICE_ADID = "advertisingId";
66+
public static final String DEVICE_SYSTEM_NAME = "systemName";
67+
public static final String DEVICE_SYSTEM_VERSION = "systemVersion";
68+
public static final String DEVICE_MODEL = "model";
69+
public static final String DEVICE_SDK_VERSION = "sdkVersion";
70+
6271
public static final String INSTANCE_ID_CLASS = "com.google.android.gms.iid.InstanceID";
63-
public static final String FIREBASE_MESSAGING_CLASS = "com.google.firebase.messaging.FirebaseMessaging";
6472
public static final String ICON_FOLDER_IDENTIFIER = "drawable";
6573
public static final String NOTIFICATION_ICON_NAME = "iterable_notification_icon";
6674
public static final String NOTIFICATION_COLOR = "iterable_notification_color";
6775
public static final String DEFAULT_SOUND = "default";
6876
public static final String SOUND_FOLDER_IDENTIFIER = "raw";
6977
public static final String ANDROID_RESOURCE_PATH = "android.resource://";
78+
public static final String ANDROID_STRING = "string";
79+
80+
//Firebase
81+
public static final String FIREBASE_RESOURCE_ID = "firebase_database_url";
82+
public static final String FIREBASE_MESSAGING_CLASS = "com.google.firebase.messaging.FirebaseMessaging";
83+
public static final String FIREBASE_COMPATIBLE = "firebaseCompatible";
84+
public static final String FIREBASE_TOKEN_TYPE = "tokenRegistrationType";
85+
public static final String FIREBASE_INITIAL_UPGRADE = "initialFirebaseUpgrade";
7086

7187
public static final String ITBL_DEEPLINK_IDENTIFIER = "/a/[A-Za-z0-9]+";
7288
public static final String DATEFORMAT = "yyyy-MM-dd HH:mm:ss";

0 commit comments

Comments
 (0)