Skip to content

Commit 236e27e

Browse files
authored
Merge pull request #728 from Iterable/MOB-8330-Support-For-Push-with-Text-Input
[MOB - 8330] - Support for push with text input
2 parents 78e6ea6 + 3a5a67a commit 236e27e

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,21 @@ private PendingIntent getPendingIntent(Context context, IterableNotificationData
129129
buttonIntent.putExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER, button.identifier);
130130
buttonIntent.putExtra(IterableConstants.ACTION_IDENTIFIER, button.identifier);
131131

132+
int pendingIntentFlag = button.buttonType.equals(IterableNotificationData.Button.BUTTON_TYPE_TEXT_INPUT) ?
133+
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE :
134+
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
135+
132136
if (button.openApp) {
133137
IterableLogger.d(TAG, "Go through TrampolineActivity");
134138
buttonIntent.setClass(context, IterableTrampolineActivity.class);
135139
buttonIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
136140
pendingButtonIntent = PendingIntent.getActivity(context, buttonIntent.hashCode(),
137-
buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
141+
buttonIntent, pendingIntentFlag);
138142
} else {
139143
IterableLogger.d(TAG, "Go through IterablePushActionReceiver");
140144
buttonIntent.setClass(context, IterablePushActionReceiver.class);
141145
pendingButtonIntent = PendingIntent.getBroadcast(context, buttonIntent.hashCode(),
142-
buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
146+
buttonIntent, pendingIntentFlag);
143147
}
144148

145149
return pendingButtonIntent;

iterableapi/src/test/java/com/iterable/iterableapi/IterableNotificationTest.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,34 @@ public void testNoAction() throws Exception {
9393
}
9494

9595
@Test
96-
public void testPendingIntentImmutable() throws Exception {
96+
public void testPendingIntentFlags() throws Exception {
9797
Bundle notif = new Bundle();
9898
notif.putString(IterableConstants.ITERABLE_DATA_KEY, getResourceString("push_payload_action_buttons.json"));
9999

100100
IterableNotificationBuilder iterableNotification = postNotification(notif);
101101
StatusBarNotification statusBarNotification = mNotificationManager.getActiveNotifications()[0];
102102
Notification notification = statusBarNotification.getNotification();
103103

104-
assertTrue((shadowOf(notification.contentIntent).getFlags() & PendingIntent.FLAG_IMMUTABLE) != 0);
105-
assertTrue((shadowOf(notification.actions[0].actionIntent).getFlags() & PendingIntent.FLAG_IMMUTABLE) != 0);
106-
assertTrue((shadowOf(notification.actions[1].actionIntent).getFlags() & PendingIntent.FLAG_IMMUTABLE) != 0);
107-
assertTrue((shadowOf(notification.actions[2].actionIntent).getFlags() & PendingIntent.FLAG_IMMUTABLE) != 0);
104+
// Test contentIntent (default action)
105+
int contentIntentFlags = shadowOf(notification.contentIntent).getFlags();
106+
assertTrue((contentIntentFlags & PendingIntent.FLAG_UPDATE_CURRENT) != 0);
107+
assertTrue((contentIntentFlags & PendingIntent.FLAG_IMMUTABLE) != 0); // Should be immutable for default action
108+
109+
// Test deeplink button (default type, openApp=true)
110+
int deeplinkButtonFlags = shadowOf(notification.actions[0].actionIntent).getFlags();
111+
assertTrue((deeplinkButtonFlags & PendingIntent.FLAG_UPDATE_CURRENT) != 0);
112+
assertTrue((deeplinkButtonFlags & PendingIntent.FLAG_IMMUTABLE) != 0); // Should be immutable for default type
113+
114+
// Test silent action button (default type, openApp=false)
115+
int silentActionFlags = shadowOf(notification.actions[1].actionIntent).getFlags();
116+
assertTrue((silentActionFlags & PendingIntent.FLAG_UPDATE_CURRENT) != 0);
117+
assertTrue((silentActionFlags & PendingIntent.FLAG_IMMUTABLE) != 0); // Should be immutable for default type
118+
119+
// Test text input button
120+
int textInputFlags = shadowOf(notification.actions[2].actionIntent).getFlags();
121+
assertTrue((textInputFlags & PendingIntent.FLAG_UPDATE_CURRENT) != 0);
122+
assertTrue((textInputFlags & PendingIntent.FLAG_MUTABLE) != 0); // Should be mutable for text input
123+
108124
}
109125

110126
}

0 commit comments

Comments
 (0)