use of com.onesignal.OSNotificationOpenResult in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldContainPayloadWhenOldSummaryNotificationIsOpened.
@Test
public void shouldContainPayloadWhenOldSummaryNotificationIsOpened() throws Exception {
OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification);
OneSignal.init(blankActivity, "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba", new OneSignal.NotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenResult result) {
lastOpenResult = result;
}
});
// Display 2 notifications that will be grouped together.
Bundle bundle = getBaseNotifBundle("UUID1");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
bundle = getBaseNotifBundle("UUID2");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
// Go forward 4 weeks
ShadowSystemClock.setCurrentTimeMillis(System.currentTimeMillis() + 2419202L * 1000L);
// Display a 3 normal notification.
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, getBaseNotifBundle("UUID3"), null);
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
// Open the summary notification
Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();
PostedNotification postedNotification = postedNotifsIterator.next().getValue();
Intent intent = Shadows.shadowOf(postedNotification.notif.contentIntent).getSavedIntent();
NotificationOpenedProcessor_processFromContext(blankActivity, intent);
// Make sure we get a payload when it is opened.
Assert.assertNotNull(lastOpenResult.notification.payload);
}
use of com.onesignal.OSNotificationOpenResult in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method testOSNotificationOpenResultToJSONObject.
@Test
public void testOSNotificationOpenResultToJSONObject() throws Exception {
OSNotificationOpenResult osNotificationOpenResult = new OSNotificationOpenResult();
osNotificationOpenResult.notification = createTestOSNotification();
osNotificationOpenResult.action = new OSNotificationAction();
osNotificationOpenResult.action.type = OSNotificationAction.ActionType.Opened;
JSONObject testJsonObj = osNotificationOpenResult.toJSONObject();
JSONObject additionalData = testJsonObj.optJSONObject("notification").optJSONObject("payload").optJSONObject("additionalData");
Assert.assertEquals("bar", additionalData.optString("foo"));
JSONObject firstGroupedNotification = (JSONObject) testJsonObj.optJSONObject("notification").optJSONArray("groupedNotifications").get(0);
Assert.assertEquals("collapseId1", firstGroupedNotification.optString("collapseId"));
}
Aggregations