Message Center

The default Message Center is provided out of the box to all customers using iOS or Android SDK 7.0.0 or later. It requires little to no integration to get started and supports some basic theming options.

Displaying the Message Center

The Message Center can be displayed any time by calling MessageCenter.getMessageCenter() . MessageCenter.showMessageCenter() . A specific message can be displayed by calling MessageCenter.showMessageCenter(java.lang.String) .

Displaying the Message Center
UAirship.shared().getMessageCenter().showMessageCenter();
UAirship.shared().getMessageCenter().showMessageCenter("Airship!");

The Airship SDK will default to showing the provided MessageCenterActivity. A custom show behavior can be accomplished by providing a MessageCenter.OnShowMessageCenterListener listener during takeOff:

  airship.getMessageCenter().setOnShowMessageCenterListener(messageId -> {
            // Show the message center (messageId is optional)
            return true;
        });

Styling the Message Center

The Message Center can be styled by providing a custom style in the application's theme with the attribute messageCenterStyle. The Message Center can be customized with the following attributes:

messageCenterItemBackground
A drawable for the message item's background
messageCenterItemTitleTextAppearance
Text appearance style for the message's title
messageCenterItemDateTextAppearance
Text appearance style for the message's date
messageCenterItemIconEnabled
Flag to enable message list icons instead of a checkbox
messageCenterItemIconPlaceholder
The default placeholder when using message list icons
messageNotSelectedTextAppearance
Text appearance style for the no message selected text when displaying the Message Center in a tablet view
messageNotSelectedText
String to use for the "no message selected" text when displaying the Message Center in a tablet view.
messageCenterEmptyMessageTextAppearance
Text appearance style for the empty message list text
messageCenterEmptyMessageText
String to use for the empty message list text
messageCenterDividerColor
The message list divider color
Example
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
   <!-- Set the custom Message Center style -->
   <item name="messageCenterStyle">@style/AppTheme.MessageCenter</item>
</style>

 <style name="AppTheme.MessageCenter" parent="MessageCenter">
     <item name="messageCenterDividerColor">#44000000</item>
     <item name="messageCenterItemIconEnabled">true</item>
     <item name="messageCenterItemTitleTextAppearance">@style/AppTheme.MessageCenter.TitleTextAppearance</item>
     <item name="messageCenterItemDateTextAppearance">@style/AppTheme.MessageCenter.DateTextAppearance</item>
 </style>

 <!-- Custom message title text style -->
 <style name="AppTheme.MessageCenter.TitleTextAppearance" parent="MessageCenter.Item.Title.TextAppearance">
     <item name="android:textSize">30sp</item>
     <item name="android:textStyle">italic</item>
     <item name="android:textColor">@android:color/black</item>
 </style>

 <!-- Custom message date text style -->
 <style name="AppTheme.MessageCenter.DateTextAppearance" parent="MessageCenter.Item.Date.TextAppearance">
     <item name="android:textSize">16sp</item>
     <item name="urbanAirshipFontPath">"fonts/CustomFont.ttf"</item>
 </style>

Message Center Filtering

Sometimes it can be useful to filter the contents of the message center according to some predetermined pattern. To facilitate this, use the shared MessageCenter instance to set a predicate. Once set, only messages that match the predicate will be displayed.

Filtering messages
RichPushInbox.Predicate pred = new RichPushInbox.Predicate() {
    @Override
    public boolean apply(RichPushMessage message) {
        return message.getTitle().contains("Cool");
    }
};

UAirship.shared().getMessageCenter().setPredicate(pred);

Embedding the Message Center

The Message Center can be embedded in any FragmentActivity using MessageCenterFragment .

Embedding the MessageCenterFragment in a layout xml
<fragment
    android:name="com.urbanairship.messagecenter.MessageCenterFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
Embedding the MessageCenterFragment using a fragment transaction
MessageCenterFragment fragment = new MessageCenterFragment();
getSupportFragmentManager().beginTransaction()
                                   .replace(R.id.content_frame, fragment, "message_center")
                                   .commit();