Search in sources :

Example 1 with OSNotificationOpenResult

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);
}
Also used : OneSignal(com.onesignal.OneSignal) ShadowOneSignal(com.onesignal.ShadowOneSignal) Bundle(android.os.Bundle) OneSignalPackagePrivateHelper.createInternalPayloadBundle(com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle) Intent(android.content.Intent) OSNotificationOpenResult(com.onesignal.OSNotificationOpenResult) PostedNotification(com.onesignal.ShadowRoboNotificationManager.PostedNotification) Test(org.junit.Test)

Example 2 with OSNotificationOpenResult

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

Aggregations

OSNotificationOpenResult (com.onesignal.OSNotificationOpenResult)2 Test (org.junit.Test)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 OSNotificationAction (com.onesignal.OSNotificationAction)1 OneSignal (com.onesignal.OneSignal)1 OneSignalPackagePrivateHelper.bundleAsJSONObject (com.onesignal.OneSignalPackagePrivateHelper.bundleAsJSONObject)1 OneSignalPackagePrivateHelper.createInternalPayloadBundle (com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle)1 ShadowOneSignal (com.onesignal.ShadowOneSignal)1 PostedNotification (com.onesignal.ShadowRoboNotificationManager.PostedNotification)1 JSONObject (org.json.JSONObject)1