Search in sources :

Example 6 with NotificationSettings

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

the class NotificationTapReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Bundle messageBundle = intent.getBundleExtra(BroadcastParameter.EXTRA_MESSAGE);
    Message message = Message.createFrom(messageBundle);
    if (message == null) {
        MobileMessagingLogger.e("Received no message in NotificationTapReceiver");
        return;
    }
    broadcaster(context).notificationTapped(message);
    NotificationSettings notificationSettings = mobileMessagingCore(context).getNotificationSettings();
    if (notificationSettings == null) {
        return;
    }
    if (notificationSettings.markSeenOnTap()) {
        mobileMessagingCore(context).setMessagesSeen(message.getMessageId());
    }
    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(Event.NOTIFICATION_TAPPED.getKey());
    callbackIntent.putExtra(BroadcastParameter.EXTRA_MESSAGE, messageBundle);
    // 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 : Message(org.infobip.mobile.messaging.Message) Bundle(android.os.Bundle) NotificationSettings(org.infobip.mobile.messaging.NotificationSettings) Intent(android.content.Intent)

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