Android App Inbox

The inbox service allows you to persist notifications you send to a user in an inbox in the App. It also allows you to send messages to users who have not opted into push notifications as these messages come into the inbox like a feed when the app is opened. You are also not constrained by the push notification format and can use a richer style in your inbox messages. 

 

Integration guides for Inbox functionality in Android apps below. Note: Make sure you have setup the inbox on the platform before you start, this is a prerequisite.

 

Enabling the Inbox

Basic Configuration

In order to be able to open the Activity that holds the inbox, an additional reference must be added into the application element of AndroidManifest.xml:

<activity
android:name="ie.imobile.extremepush.ui.InboxActivity"
android:label="@string/title_activity_inbox"
android:theme="@style/Theme.Transparent"
android:configChanges="orientation|screenSize" />

 

In the standard integration described in the Android integration guide the inbox is switched off.  It can be turned on using the setInboxEnabled method. In your Android app, where you initialise the PushConnector objects, add the following:

.setInboxEnabled(true)

As shown below:

mPushConnector = new PushConnector.Builder(XPUSH_APP_KEY, GOOGLE_PROJECT_NUMBER)
// ...
.setInboxEnabled(true)
// ...
.create(this);

 

You will also need to add a UI element (Button) to launch the inbox. When tapped this button will open the inbox. You may, for example, want to add an inbox icon to your action bar menu or elsewhere in your activity:

To add the default ImageButton into the app's action bar, override the onCreateOptionsMenu function in your Activity and call the inflateInboxMenuItem function as seen here:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
mPushConnector.inflateInboxMenuItem(menu, this);
return true;
}

 

At this point, the inbox is fully integrated into your app and can be opened by clicking on the icon in the action bar menu. Additionally, badges with a count of new items in your inbox will be displayed automatically on the inbox button, as seen here:

 

Configure Proguard Rules for the Inbox

If you are using Proguard rules for building your release version of the app, the inbox functionality needs an additional set of rules. Please add the following to your proguard-rules.pro file:

# Required for inbox functionality
-keepclassmembers class * {
 @android.webkit.JavascriptInterface <methods>;
}

# Required for inbox functionality
-keepattributes JavascriptInterface
-keep public class ie.imobile.extremepush.ui.InboxActivity$InboxInterface
-keep public class * implements ie.imobile.extremepush.ui.InboxActivity$InboxInterface
-keepclassmembers class ie.imobile.extremepush.ui.InboxActivity$InboxInterface {
 <methods>;
}

The full list of Proguard rules required for the Xtremepush SDK can be found on the Android Integration page.

 

 

Advanced Configuration Options 

There are some advanced configurations options, described here, that allow you to perform the following tasks if necessary for your app:

  1. Change the inbox button icon and/or set the icon colour
  2. Disable badges on the inbox button
  3. Change the badge background and text colours
  4. Place the inbox button somewhere other than the action bar menu
  5. Use your own button for opening the inbox

Each of these options will now be described in turn:

 

1. Change Inbox Icon or Icon Colour

Similar to how the notification icon can be configured for your app, the setInboxIcon function can be used for changing the icon on the inbox button. It can also be used to change the icon's colour too.

mPushConnector = new PushConnector.Builder(XPUSH_APP_KEY, GOOGLE_PROJECT_NUMBER)
.setInboxEnabled(true)
.setInboxIcon("iconfilenamewithoutextension")
.create(this)

This will set the icon for the inbox button with an image from the res/drawable folder of the app. In this example, the library will try to look for a file called iconfilenamewithoutextension.jpg or iconfilenamewithoutextension.png etc. in the res/drawable folder. If the file cannot be found, the default inbox button icon will be used instead. 

The library will also search for a "color" entry with the same name in one of the XML files in the res/values to use as a colour filter over the icon. In this way you can set the colour of the icon. If no matching colour is found in res/values then no filter is applied to the icon. The entry in res/values could look like the following:

<!-- color int as #AARRGGBB (alpha, red, green, blue) -->
<color name="iconfilenamewithoutextension">#ff2266ff</color>

Here, the icon has been changed and a colour filter has been applied to it:

 

2. Disable Badges on the Inbox Button

You may wish to disable the badges on the inbox button within your app. To do this, please use the setInboxBadgeEnabled function as seen here:

mPushConnector = new PushConnector.Builder(XPUSH_APP_KEY, GOOGLE_PROJECT_NUMBER)
.setInboxEnabled(true)
.setInboxBadgeEnabled(false)
.create(this)

 

3. Change the Badge Background and Text Colours

The default colours for the inbox button badge consists of a red background and white text. If you wish to change these values, you can use the setInboxBadgeColors function, passing in a background and text colour respectively as parameters. The example below shows the code required for setting blue as the background colour and yellow as the text colour.

mPushConnector = new PushConnector.Builder(XPUSH_APP_KEY, GOOGLE_PROJECT_NUMBER)
.setInboxEnabled(true)
.setInboxBadgeColors("#ff0000ff", "#ffffff00")
.create(this)

 

4. Place the Inbox Button Somewhere Other than the Action Bar Menu

The steps above have described how the inbox button can be added to action bar menu in the app. The same button can also be added elsewhere in the app, instead of (or in conjunction with) the button in the action bar menu. To place our inbox button somewhere else in your app other than the action bar menu, there are three steps involved:

First, add a reference to the inbox button in the desired location in your layout XML files. This requires a single line:

<include layout="@layout/xp_inbox_button" />

Secondly, for any Activities using the above XML layouts, an onClickListener will need to be added to the inbox button. This can be performed by implementing View.OnClickListener in the Activity and then adding the following to the onCreate function of the Activity:

ImageButton inboxButton = (ImageButton) findViewById(R.id.xp_inbox_button);
inboxButton.setOnClickListener(this);

Finally, in the onClick callback function, open the inbox using the openInbox function, passing in a reference to the activity.

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.xp_inbox_button:
mPushConnector.openInbox(this);
break;
}
}

 

5. Use your own Button for Opening the Inbox

If you wish to use your own button for the purposes of opening the inbox, this can be achieved using the openInbox function. This can be seen just above, where the following code is used in the onClick function of the Activity class.

mPushConnector.openInbox(this);

If you wish to handle the badge numbers too, we have created an InboxBadgeListener interface that can be implemented by your Activity. When this is done, your Activity will receive a callback whenever the inbox badge number is updated. Here is the function that will be called on a badge number update:

@Override
public void inboxBadgeUpdated(int badge) {
//Handle badge number here
}
Have more questions? Submit a request

0 Comments

Article is closed for comments.