Search in sources :

Example 6 with NotificationAction

use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.

the class NotificationActionTapReceiverTest method test_should_trigger_sdk_actions_when_clicked_on_action_button.

@Test
public void test_should_trigger_sdk_actions_when_clicked_on_action_button() throws Exception {
    // Given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").withMoMessage().build();
    NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
    Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, 1234, notificationSettings.getIntentFlags());
    // When
    notificationActionTapReceiver.onReceive(contextMock, givenIntent);
    // Then
    Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
    Message actualMessage = messageArgumentCaptor.getValue();
    NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
    NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
    Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Intent(android.content.Intent) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory) Test(org.junit.Test)

Example 7 with NotificationAction

use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.

the class AndroidInteractiveBroadcasterTest method test_should_send_notification_action_tapped_event.

@Test
public void test_should_send_notification_action_tapped_event() throws Exception {
    // Given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    NotificationAction notificationAction = givenNotificationAction("actionIdNotTapped").build();
    NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").build();
    NotificationCategory givenNotificationCategory = new NotificationCategory("categoryId", notificationAction, givenTappedNotificationAction);
    // When
    broadcastSender.notificationActionTapped(givenMessage, givenNotificationCategory, givenTappedNotificationAction);
    // Then
    Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
    Intent intent = intentArgumentCaptor.getValue();
    assertEquals(InteractiveEvent.NOTIFICATION_ACTION_TAPPED.getKey(), intent.getAction());
    Message messageAfter = Message.createFrom(intent.getExtras());
    NotificationAction actionAfter = NotificationAction.createFrom(intent.getExtras());
    NotificationCategory categoryAfter = NotificationCategory.createFrom(intent.getExtras());
    assertNotSame(message, messageAfter);
    assertEquals("SomeMessageId", messageAfter.getMessageId());
    assertJEquals(givenMessage, messageAfter);
    assertJEquals(givenTappedNotificationAction, actionAfter);
    assertJEquals(givenNotificationCategory, categoryAfter);
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Intent(android.content.Intent) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory) Test(org.junit.Test)

Example 8 with NotificationAction

use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.

the class InteractiveNotificationHandler method setNotificationActions.

private void setNotificationActions(NotificationCompat.Builder notificationBuilder, Message message, NotificationCategory triggeredNotificationCategory, int notificationId) {
    if (triggeredNotificationCategory == null) {
        return;
    }
    NotificationAction[] notificationActions = triggeredNotificationCategory.getNotificationActions();
    for (NotificationAction notificationAction : notificationActions) {
        PendingIntent pendingIntent = createActionTapPendingIntent(message, triggeredNotificationCategory, notificationAction, notificationId);
        notificationBuilder.addAction(createAndroidNotificationAction(notificationAction, pendingIntent));
    }
}
Also used : NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) PendingIntent(android.app.PendingIntent)

Aggregations

NotificationAction (org.infobip.mobile.messaging.interactive.NotificationAction)8 Intent (android.content.Intent)5 Message (org.infobip.mobile.messaging.Message)5 NotificationCategory (org.infobip.mobile.messaging.interactive.NotificationCategory)5 Test (org.junit.Test)4 PendingIntent (android.app.PendingIntent)1 Bundle (android.os.Bundle)1 NotificationSettings (org.infobip.mobile.messaging.NotificationSettings)1