Search in sources :

Example 1 with NotificationSettings

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);
}
Also used : Message(org.infobip.mobile.messaging.Message) MockActivity(org.infobip.mobile.messaging.interactive.platform.MockActivity) NotificationSettings(org.infobip.mobile.messaging.NotificationSettings) MobileMessagingCore(org.infobip.mobile.messaging.MobileMessagingCore)

Example 2 with 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);
}
Also used : NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) NotificationSettings(org.infobip.mobile.messaging.NotificationSettings) Intent(android.content.Intent)

Example 3 with NotificationSettings

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;
}
Also used : NotificationSettings(org.infobip.mobile.messaging.NotificationSettings) NotificationCompat(android.support.v4.app.NotificationCompat)

Example 4 with NotificationSettings

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;
}
Also used : NotificationSettings(org.infobip.mobile.messaging.NotificationSettings)

Example 5 with NotificationSettings

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);
}
Also used : NotificationSettings(org.infobip.mobile.messaging.NotificationSettings)

Aggregations

NotificationSettings (org.infobip.mobile.messaging.NotificationSettings)6 Intent (android.content.Intent)2 Message (org.infobip.mobile.messaging.Message)2 Bundle (android.os.Bundle)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 MobileMessagingCore (org.infobip.mobile.messaging.MobileMessagingCore)1 NotificationAction (org.infobip.mobile.messaging.interactive.NotificationAction)1 MockActivity (org.infobip.mobile.messaging.interactive.platform.MockActivity)1