Android App Inbox API

To start using the App Inbox feature, first make sure you have followed the integration guide.

The App Inbox is a great feature to keep all the messages in one place, allowing users to read messages even after they have dismissed a notification. Your application is in charge of managing and displaying the messages.

An App Inbox message is a simple class proxy that only exposes the required information like the title, content, and the message read status. An App Inbox message can be actionable, meaning it can perform an action when selected, like opening a deep link or display an image. Executing a message action will mark the message as read.

The App Inbox provides a simple API for accessing the messages, removing them or change their status. For example, the getUnreadMessageCount can be used to display a badge with the number of messages that require the users's attention.

To display the App Inbox messages, you could for example use a RecyclerView with a basic cell showing the title and subtitle. Set the text font weight to bold when unread. When user selects a row that is actionable, just call the inbox.executeMessage(message).

note

The sample application available on Github here shows a simple RecyclerView implementation.

Handling App Inbox Events

You can register to broadcast intents sent by the App Inbox when a message is added to the inbox, read (from notification), or has expired.

// Intent action for event broadcast
public final static String APP_INBOX_ACTION
// Intent extra with event name
public final static String APP_INBOX_EVENT_EXTRA
// Intent extra with unread count
public final static String APP_INBOX_UNREAD_EXTRA
// A message was read event
public final static String APP_INBOX_MESSAGE_READ
// A message was added event
public final static String APP_INBOX_MESSAGE_ADDED
// A message expired event
public final static String APP_INBOX_MESSAGE_EXPIRED

The broadcast intent with action APP_INBOX_ACTION comes with 2 extra fields:

  • APP_INBOX_EVENT_EXTRA: (String) The event type (added, read, expired)
  • APP_INBOX_UNREAD_EXTRA: (long) The number of unread messages after the event occured

Example:

public class InboxActivity extends AppCompatActivity {
private BroadcastReceiver inboxBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String event = intent.getStringExtra(OpenBack.APP_INBOX_EVENT_EXTRA);
long unread = intent.getLongExtra(OpenBack.APP_INBOX_UNREAD_EXTRA, 0);
switch (event) {
case OpenBack.APP_INBOX_MESSAGE_ADDED:
case OpenBack.APP_INBOX_MESSAGE_READ:
case OpenBack.APP_INBOX_MESSAGE_EXPIRED:
// Handle inbox changes (e.g. refresh list, update badge...)
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
LocalBroadcastManager.getInstance(getApplicationContext())
.registerReceiver(inboxBroadcastReceiver, new IntentFilter(OpenBack.APP_INBOX_ACTION));
}
@Override
protected void onStop() {
super.onStop();
...
LocalBroadcastManager.getInstance(getApplicationContext())
.unregisterReceiver(inboxBroadcastReceiver);
}
}