Skip to content

Commit 2478a82

Browse files
committed
Adds checks to not process push notifications for the app not from Iterable.
1 parent 55bd224 commit 2478a82

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

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

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,37 @@ private void handlePushRegistration(Context context, Intent intent) {
4040
}
4141

4242
private void handlePushReceived(Context context, Intent intent) {
43-
Context appContext = context.getApplicationContext();
44-
45-
PackageManager packageManager = appContext.getPackageManager();
46-
Intent packageIntent = packageManager.getLaunchIntentForPackage(appContext.getPackageName());
47-
ComponentName componentPackageName = packageIntent.getComponent();
48-
String mainClassName = componentPackageName.getClassName();
49-
Class mainClass = null;
50-
try {
51-
mainClass = Class.forName(mainClassName);
52-
} catch (ClassNotFoundException e) {
53-
e.printStackTrace();
54-
}
43+
if (intent.hasExtra(IterableConstants.ITERABLE_DATA_KEY)) {
44+
Context appContext = context.getApplicationContext();
45+
PackageManager packageManager = appContext.getPackageManager();
46+
Intent packageIntent = packageManager.getLaunchIntentForPackage(appContext.getPackageName());
47+
ComponentName componentPackageName = packageIntent.getComponent();
48+
String mainClassName = componentPackageName.getClassName();
49+
Class mainClass = null;
50+
try {
51+
mainClass = Class.forName(mainClassName);
52+
} catch (ClassNotFoundException e) {
53+
e.printStackTrace();
54+
}
5555

56-
int iconId = appContext.getResources().getIdentifier(
57-
IterableApi.getNotificationIcon(context),
58-
"drawable",
59-
appContext.getPackageName());
56+
int iconId = appContext.getResources().getIdentifier(
57+
IterableApi.getNotificationIcon(context),
58+
"drawable",
59+
appContext.getPackageName());
6060

61-
if (iconId == 0) {
62-
iconId = appContext.getApplicationInfo().icon;
63-
if (iconId != 0){
64-
Log.d(TAG, "No Notification Icon defined - defaulting to app icon");
65-
} else {
66-
Log.w(TAG, "No Notification Icon defined - push notifications will not be displayed");
61+
if (iconId == 0) {
62+
iconId = appContext.getApplicationInfo().icon;
63+
if (iconId != 0) {
64+
Log.d(TAG, "No Notification Icon defined - defaulting to app icon");
65+
} else {
66+
Log.w(TAG, "No Notification Icon defined - push notifications will not be displayed");
67+
}
6768
}
68-
}
6969

70-
IterableNotification notificationBuilder = IterableNotification.createNotification(
71-
appContext, intent.getExtras(), mainClass, iconId);
70+
IterableNotification notificationBuilder = IterableNotification.createNotification(
71+
appContext, intent.getExtras(), mainClass, iconId);
7272

73-
IterableNotification.postNotificationOnDevice(appContext, notificationBuilder);
73+
IterableNotification.postNotificationOnDevice(appContext, notificationBuilder);
74+
}
7475
}
7576
}

0 commit comments

Comments
 (0)