Search in sources :

Example 1 with OSNotificationOpenedResult

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);
}
Also used : OneSignal(com.onesignal.OneSignal) ShadowOneSignal(com.onesignal.ShadowOneSignal) OSNotificationOpenedResult(com.onesignal.OSNotificationOpenedResult) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) JSONArray(org.json.JSONArray) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) Test(org.junit.Test)

Example 2 with OSNotificationOpenedResult

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());
}
Also used : BigInteger(java.math.BigInteger) OneSignal(com.onesignal.OneSignal) ShadowOneSignal(com.onesignal.ShadowOneSignal) OSNotificationOpenedResult(com.onesignal.OSNotificationOpenedResult) Bundle(android.os.Bundle) FCMBroadcastReceiver_processBundle(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_processBundle) OneSignalPackagePrivateHelper.createInternalPayloadBundle(com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle) FCMBroadcastReceiver_onReceived_withIntent(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PostedNotification(com.onesignal.ShadowRoboNotificationManager.PostedNotification) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with OSNotificationOpenedResult

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"));
}
Also used : OSNotificationOpenedResult(com.onesignal.OSNotificationOpenedResult) JSONObject(org.json.JSONObject) OSNotificationAction(com.onesignal.OSNotificationAction) Test(org.junit.Test)

Example 4 with OSNotificationOpenedResult

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 + "]"));
}
Also used : OneSignal(com.onesignal.OneSignal) ShadowOneSignal(com.onesignal.ShadowOneSignal) OSNotificationOpenedResult(com.onesignal.OSNotificationOpenedResult) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Aggregations

OSNotificationOpenedResult (com.onesignal.OSNotificationOpenedResult)4 Test (org.junit.Test)4 OneSignal (com.onesignal.OneSignal)3 ShadowOneSignal (com.onesignal.ShadowOneSignal)3 JSONArray (org.json.JSONArray)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 MockOSSharedPreferences (com.onesignal.MockOSSharedPreferences)1 MockSessionManager (com.onesignal.MockSessionManager)1 OSNotificationAction (com.onesignal.OSNotificationAction)1 FCMBroadcastReceiver_onReceived_withIntent (com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withIntent)1 FCMBroadcastReceiver_processBundle (com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_processBundle)1 OneSignalPackagePrivateHelper.createInternalPayloadBundle (com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle)1 PostedNotification (com.onesignal.ShadowRoboNotificationManager.PostedNotification)1 OSTrackerFactory (com.onesignal.influence.data.OSTrackerFactory)1 BigInteger (java.math.BigInteger)1 JSONObject (org.json.JSONObject)1 Config (org.robolectric.annotation.Config)1