use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.
the class NotificationActionTapReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
Bundle actionBundle = intent.getBundleExtra(EXTRA_TAPPED_ACTION);
Bundle categoryBundle = intent.getBundleExtra(EXTRA_TAPPED_CATEGORY);
int notificationId = intent.getIntExtra(BroadcastParameter.EXTRA_NOTIFICATION_ID, -1);
Bundle messageBundle = intent.getBundleExtra(BroadcastParameter.EXTRA_MESSAGE);
Message message = Message.createFrom(messageBundle);
NotificationCategory notificationCategory = NotificationCategory.createFrom(categoryBundle);
NotificationAction notificationAction = NotificationAction.createFrom(actionBundle);
String inputText = getInputTextFromIntent(intent, notificationAction);
cancelNotification(context, notificationId);
if (message == null) {
MobileMessagingLogger.e("Received no message in NotificationActionTapReceiver");
return;
}
if (notificationAction == null) {
MobileMessagingLogger.e("Received no action in NotificationActionTapReceiver");
return;
}
if (notificationCategory == null) {
MobileMessagingLogger.e("Received no notification category in NotificationActionTapReceiver");
return;
}
if (inputText != null) {
notificationAction.setInputText(inputText);
}
broadcaster(context).notificationActionTapped(message, notificationCategory, notificationAction);
mobileInteractive(context).triggerSdkActionsFor(notificationCategory.getCategoryId(), notificationAction, message);
startCallbackActivity(context, intent, messageBundle, actionBundle, categoryBundle);
}
use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.
the class NotificationActionTapReceiver method startCallbackActivity.
private void startCallbackActivity(Context context, Intent intent, Bundle messageBundle, Bundle actionBundle, Bundle categoryBundle) {
NotificationAction notificationAction = NotificationActionBundleMapper.notificationActionFromBundle(actionBundle);
if (notificationAction == null) {
return;
}
if (!notificationAction.bringsAppToForeground()) {
return;
}
NotificationSettings notificationSettings = mobileMessagingCore(context).getNotificationSettings();
if (notificationSettings == null) {
return;
}
Class callbackActivity = notificationSettings.getCallbackActivity();
if (callbackActivity == null) {
MobileMessagingLogger.e("Callback activity is not set, cannot proceed");
return;
}
int intentFlags = intent.getIntExtra(MobileMessagingProperty.EXTRA_INTENT_FLAGS.getKey(), (Integer) MobileMessagingProperty.INTENT_FLAGS.getDefaultValue());
Intent callbackIntent = new Intent(context, callbackActivity);
callbackIntent.setAction(InteractiveEvent.NOTIFICATION_ACTION_TAPPED.getKey());
callbackIntent.putExtras(messageBundle);
callbackIntent.putExtras(actionBundle);
callbackIntent.putExtras(categoryBundle);
// FLAG_ACTIVITY_NEW_TASK has to be here because we're starting activity outside of activity context
callbackIntent.addFlags(intentFlags | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callbackIntent);
}
use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.
the class NotificationActionTapReceiverTest method test_should_send_notification_action_clicked_event.
@Test
public void test_should_send_notification_action_clicked_event() throws Exception {
// Given
Message givenMessage = createMessage(context, "SomeMessageId", false);
int givenNotificationId = 1234;
NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").build();
NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, givenNotificationId, notificationSettings.getIntentFlags());
// When
notificationActionTapReceiver.onReceive(contextMock, givenIntent);
// Then
Mockito.verify(notificationManagerMock, Mockito.times(1)).cancel(givenNotificationId);
Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
Message actualMessage = messageArgumentCaptor.getValue();
assertJEquals(givenTappedNotificationAction, actualAction);
assertJEquals(givenNotificationCategory, actualCategory);
assertJEquals(givenMessage, actualMessage);
Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
Mockito.verify(contextMock, Mockito.never()).startActivity(any(Intent.class));
}
use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.
the class NotificationActionTapReceiverTest method test_should_send_action_clicked_event_and_open_activity.
@Test
public void test_should_send_action_clicked_event_and_open_activity() throws Exception {
// Given
Message givenMessage = createMessage(context, "SomeMessageId", false);
int givenNotificationId = 1234;
NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").withBringingAppToForeground(true).build();
NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, givenNotificationId, notificationSettings.getIntentFlags());
// When
notificationActionTapReceiver.onReceive(contextMock, givenIntent);
// Then
Mockito.verify(notificationManagerMock, Mockito.times(1)).cancel(givenNotificationId);
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();
assertJEquals(givenNotificationCategory, actualCategory);
assertJEquals(givenMessage, actualMessage);
assertJEquals(givenTappedNotificationAction, actualAction);
Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
Mockito.verify(contextMock, Mockito.times(1)).startActivity(intentArgumentCaptor.capture());
Intent actualIntent = intentArgumentCaptor.getValue();
NotificationAction actualTappedAction = NotificationAction.createFrom(actualIntent.getExtras());
NotificationCategory actualTappedCategory = NotificationCategory.createFrom(actualIntent.getExtras());
Message actualTappedMessage = Message.createFrom(actualIntent.getExtras());
assertEquals(givenIntent.getAction(), actualIntent.getAction());
assertEquals(notificationSettings.getIntentFlags() | Intent.FLAG_ACTIVITY_NEW_TASK, actualIntent.getFlags());
assertJEquals(givenTappedNotificationAction, actualTappedAction);
assertJEquals(givenNotificationCategory, actualTappedCategory);
assertJEquals(givenMessage, actualTappedMessage);
}
use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.
the class MainActivity method onNotificationActionTapped.
private void onNotificationActionTapped(Intent intent) {
NotificationAction action = NotificationAction.createFrom(intent.getExtras());
if (action == null)
return;
String actionTappedText = String.format(Locale.getDefault(), getString(R.string.toast_notification_action_tapped), action.getId());
Toast.makeText(MainActivity.this, actionTappedText, Toast.LENGTH_LONG).show();
updateCount();
}
Aggregations