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 RichPushInbox.startInboxActivity() . A specific message can be displayed by calling RichPushInbox.startMessageActivity :

Displaying the Message Center
UAirship.shared().getInbox().startInboxActivity();

RichPushInbox.startInboxActivity() will either launch the MessageCenterActivity or it can be customized by the application by adding the appropriate intent filters to an activity in the AndroidManifest.xml.

Message Center Display intent filter
<intent-filter>
    <action android:name="com.urbanairship.VIEW_RICH_PUSH_INBOX" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<div class="u-bg-black u-white u-text-bold u-text-shrink-1 u-pad-1 u-space-top-1 u-space-bottom-none">
  Displaying a specific message
</div>


<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">UAirship<span style="color:#f92672">.</span><span style="color:#a6e22e">shared</span><span style="color:#f92672">().</span><span style="color:#a6e22e">getInbox</span><span style="color:#f92672">().</span><span style="color:#a6e22e">startMessageActivity</span><span style="color:#f92672">(</span>messageId<span style="color:#f92672">);</span></code></pre></div>

<!-- Route message displays through a Message Center -->
<intent-filter>
    <action android:name="com.urbanairship.VIEW_RICH_PUSH_INBOX" />
    <data android:scheme="message"/>
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Message display intent filter
<intent-filter>
    <action android:name="com.urbanairship.VIEW_RICH_PUSH_MESSAGE" />
    <data android:scheme="message"/>
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Parsing message from intents
RichPushMessage message = null;

if (RichPushInbox.VIEW_INBOX_INTENT_ACTION.equals(intent.getAction()) {
    if (getIntent().getData().getScheme().equalsIgnoreCase(RichPushInbox.MESSAGE_DATA_SCHEME)) {
        String messageId = getIntent().getData().getSchemeSpecificPart();
        message = UAirship.shared().getInbox().getMessage(messageId);
    }
}

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
urbanAirshipFontPath
Text appearance attribute that defines a path to custom font in the assets directory
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>
     <item name="urbanAirshipFontPath">"fonts/CustomFont.ttf"</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();