Skip to content

Commit 29ae565

Browse files
authored
Merge pull request #25 from Iterable/feature/ITBL-3821-OS-notification-payload
Feature/itbl 3821 os notification payload
2 parents 1d416ae + 6ebbc53 commit 29ae565

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,18 @@ static boolean isGhostPush(Bundle extras) {
243243

244244
return isGhostPush;
245245
}
246+
247+
/**
248+
* Returns if the given notification has an empty body
249+
* @param extras
250+
* @return
251+
*/
252+
static boolean isEmptyBody(Bundle extras) {
253+
String notificationBody = "";
254+
if (extras.containsKey(IterableConstants.ITERABLE_DATA_KEY)) {
255+
notificationBody = extras.getString(IterableConstants.ITERABLE_DATA_BODY, "");
256+
}
257+
258+
return notificationBody.isEmpty();
259+
}
246260
}

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,26 @@ private void handlePushReceived(Context context, Intent intent) {
4646
if (intent.hasExtra(IterableConstants.ITERABLE_DATA_KEY)) {
4747
Bundle extras = intent.getExtras();
4848
if (!IterableNotification.isGhostPush(extras)) {
49-
IterableLogger.d(TAG, "Iterable push received " + extras);
50-
Context appContext = context.getApplicationContext();
51-
PackageManager packageManager = appContext.getPackageManager();
52-
Intent packageIntent = packageManager.getLaunchIntentForPackage(appContext.getPackageName());
53-
ComponentName componentPackageName = packageIntent.getComponent();
54-
String mainClassName = componentPackageName.getClassName();
55-
Class mainClass = null;
56-
try {
57-
mainClass = Class.forName(mainClassName);
58-
} catch (ClassNotFoundException e) {
59-
IterableLogger.w(TAG, e.toString());
60-
}
49+
if (!IterableNotification.isEmptyBody(extras)) {
50+
IterableLogger.d(TAG, "Iterable push received " + extras);
51+
Context appContext = context.getApplicationContext();
52+
PackageManager packageManager = appContext.getPackageManager();
53+
Intent packageIntent = packageManager.getLaunchIntentForPackage(appContext.getPackageName());
54+
ComponentName componentPackageName = packageIntent.getComponent();
55+
String mainClassName = componentPackageName.getClassName();
56+
Class mainClass = null;
57+
try {
58+
mainClass = Class.forName(mainClassName);
59+
} catch (ClassNotFoundException e) {
60+
IterableLogger.w(TAG, e.toString());
61+
}
6162

62-
IterableNotification notificationBuilder = IterableNotification.createNotification(
63-
appContext, intent.getExtras(), mainClass);
64-
new IterableNotificationBuilder().execute(notificationBuilder);
63+
IterableNotification notificationBuilder = IterableNotification.createNotification(
64+
appContext, intent.getExtras(), mainClass);
65+
new IterableNotificationBuilder().execute(notificationBuilder);
66+
} else {
67+
IterableLogger.d(TAG, "Iterable OS notification push received");
68+
}
6569
} else {
6670
IterableLogger.d(TAG, "Iterable ghost silent push received");
6771
}

0 commit comments

Comments
 (0)