use of com.onesignal.OSNotificationOpenedResult in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method testOnV2CorrectOutcomeSent_fromNotificationOpenedHandler.
@Test
public void testOnV2CorrectOutcomeSent_fromNotificationOpenedHandler() throws Exception {
// Enable IAM v2
preferences = new MockOSSharedPreferences();
trackerFactory = new OSTrackerFactory(preferences, logger, time);
sessionManager = new MockSessionManager(sessionListener, trackerFactory, logger);
preferences.saveBool(preferences.getPreferencesName(), preferences.getOutcomesV2KeyName(), true);
OneSignal_setSharedPreferences(preferences);
// Init OneSignal with a custom opened handler
OneSignalInit(new OneSignal.OSNotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenedResult result) {
OneSignal.sendOutcome(ONESIGNAL_OUTCOME_NAME);
}
});
threadAndTaskWait();
// Background app
pauseActivity(blankActivityController);
// Receive and open a notification
OneSignal_handleNotificationOpen(blankActivity, new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\" } }]"), false, ONESIGNAL_NOTIFICATION_ID);
threadAndTaskWait();
// Foreground the application
blankActivityController.resume();
threadAndTaskWait();
JSONArray notificationIds = new JSONArray();
notificationIds.put(ONESIGNAL_NOTIFICATION_ID);
// Make sure a measure request is made with the correct session and notifications
assertMeasureOnV2AtIndex(3, ONESIGNAL_OUTCOME_NAME, new JSONArray(), notificationIds, null, null);
}
use of com.onesignal.OSNotificationOpenedResult in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldContainPayloadWhenOldSummaryNotificationIsOpened.
@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void shouldContainPayloadWhenOldSummaryNotificationIsOpened() throws Exception {
OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
OneSignal.initWithContext(blankActivity);
OneSignal.setNotificationOpenedHandler(new OneSignal.OSNotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenedResult result) {
lastOpenResult = result;
}
});
// Display 2 notifications that will be grouped together.
Bundle bundle = getBaseNotifBundle("UUID1");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, bundle);
bundle = getBaseNotifBundle("UUID2");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, bundle);
// Go forward 4 weeks
time.advanceSystemTimeBy(2_419_202);
// Display a 3 normal notification.
NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, getBaseNotifBundle("UUID3"));
threadAndTaskWait();
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);
threadAndTaskWait();
// Make sure we get a payload when it is opened.
assertNotNull(lastOpenResult.getNotification().getBody());
// Make sure that the summary head notification is the second one, because the third was opened
assertEquals("UUID2", lastOpenResult.getNotification().getNotificationId());
}
use of com.onesignal.OSNotificationOpenedResult in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method testOSNotificationOpenResultToJSONObject.
@Test
public void testOSNotificationOpenResultToJSONObject() throws Exception {
OSNotificationAction action = new OSNotificationAction(OSNotificationAction.ActionType.Opened, null);
OSNotificationOpenedResult osNotificationOpenedResult = new OSNotificationOpenedResult(createTestOSNotification(), action);
JSONObject testJsonObj = osNotificationOpenedResult.toJSONObject();
JSONObject additionalData = testJsonObj.optJSONObject("notification").optJSONObject("additionalData");
assertEquals("bar", additionalData.optString("foo"));
JSONObject firstGroupedNotification = (JSONObject) testJsonObj.optJSONObject("notification").optJSONArray("groupedNotifications").get(0);
assertEquals("collapseId1", firstGroupedNotification.optString("collapseId"));
}
use of com.onesignal.OSNotificationOpenedResult in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method testCorrectOutcomeSent_fromNotificationOpenedHandler.
@Test
public void testCorrectOutcomeSent_fromNotificationOpenedHandler() throws Exception {
// Init OneSignal with a custom opened handler
OneSignalInit(new OneSignal.OSNotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenedResult result) {
OneSignal.sendOutcome(ONESIGNAL_OUTCOME_NAME);
}
});
threadAndTaskWait();
// Background app
pauseActivity(blankActivityController);
// Receive and open a notification
OneSignal_handleNotificationOpen(blankActivity, new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\" } }]"), false, ONESIGNAL_NOTIFICATION_ID);
threadAndTaskWait();
// Foreground the application
blankActivityController.resume();
threadAndTaskWait();
// Make sure a measure request is made with the correct session and notifications
assertMeasureAtIndex(3, true, ONESIGNAL_OUTCOME_NAME, new JSONArray("[" + ONESIGNAL_NOTIFICATION_ID + "]"));
}
Aggregations