use of org.infobip.mobile.messaging.NotificationSettings in project mobile-messaging-sdk-android by infobip.
the class NotificationCategoriesTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
mmcMock = mock(MobileMessagingCore.class);
mobileInteractive = new MobileInteractiveImpl(contextMock, mmcMock);
messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
messageIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
NotificationSettings notificationSettings = new NotificationSettings.Builder(context).withDefaultIcon(// if not set throws -> IllegalArgumentException("defaultIcon doesn't exist");
android.R.drawable.ic_dialog_alert).withCallbackActivity(MockActivity.class).build();
Mockito.when(mmcMock.getNotificationSettings()).thenReturn(notificationSettings);
}
use of org.infobip.mobile.messaging.NotificationSettings 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.NotificationSettings in project mobile-messaging-sdk-android by infobip.
the class CoreNotificationHandler method notificationCompatBuilder.
/**
* Gets notification builder for Message.
*
* @param message message to display notification for.
* @return builder
*/
public NotificationCompat.Builder notificationCompatBuilder(Message message) {
NotificationSettings notificationSettings = notificationSettings(message);
if (notificationSettings == null)
return null;
String title = StringUtils.isNotBlank(message.getTitle()) ? message.getTitle() : notificationSettings.getDefaultTitle();
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, getChannelIdForNotification(notificationSettings)).setContentTitle(title).setContentText(message.getBody()).setAutoCancel(notificationSettings.isNotificationAutoCancel()).setContentIntent(createTapPendingIntent(notificationSettings, message)).setWhen(message.getReceivedTimestamp());
setNotificationStyle(notificationBuilder, message, title);
setNotificationSoundAndVibrate(notificationBuilder, message);
setNotificationIcon(notificationBuilder, message);
setPriorityForHeadsupNotification(notificationBuilder, notificationSettings);
return notificationBuilder;
}
use of org.infobip.mobile.messaging.NotificationSettings in project mobile-messaging-sdk-android by infobip.
the class CoreNotificationHandler method getNotificationId.
/**
* Gets notification ID for the given message
*
* @param message Message object used for setting notification ID
* @return notification ID
*/
public int getNotificationId(Message message) {
NotificationSettings settings = notificationSettings(message);
if (settings == null) {
return DEFAULT_NOTIFICATION_ID;
}
boolean areMultipleNotificationsEnabled = settings.areMultipleNotificationsEnabled();
return areMultipleNotificationsEnabled ? message.getMessageId().hashCode() : DEFAULT_NOTIFICATION_ID;
}
use of org.infobip.mobile.messaging.NotificationSettings in project mobile-messaging-sdk-android by infobip.
the class CoreNotificationHandler method setNotificationIcon.
private void setNotificationIcon(NotificationCompat.Builder notificationBuilder, Message message) {
NotificationSettings notificationSettings = notificationSettings(message);
if (notificationSettings == null)
return;
int icon;
if (StringUtils.isNotBlank(message.getIcon())) {
icon = ResourceLoader.loadResourceByName(context, "drawable", message.getIcon());
} else {
icon = notificationSettings.getDefaultIcon();
}
notificationBuilder.setSmallIcon(icon);
}
Aggregations