Skip to content

App Inbox API (SDK) Docs

This section is dedicated to the various functions available within the OpenBack SDK.

To start using the App Inbox feature, first make sure you have followed the integration guide. Then add the following imports to the file(s) where you plan to use the App Inbox:

import com.openback.OpenBack;
import com.openback.OpenBackAppInbox;
import com.openback.OpenBackAppInboxMessage;

The App Inbox is a great feature to keep all the messages in one place, allowing users to read messages even after they 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).

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

Getting the App Inbox

public static OpenBackAppInbox appInbox(Context context)

If your OpenBack application supports App Inbox, get the App Inbox associated to your application App Code from the main OpenBack class.

Example:

OpenBackAppInbox inbox = OpenBack.appInbox(getApplicationContext());
OpenBackAppInbox inbox = OpenBack.appInbox(applicationContext)

App Inbox API

Class OpenBackAppInbox methods are all blocking. To ensure a good user experience, do not call these methods from the main thread.

getMessageCount

public long getMessageCount()

Total number of messages in inbox.

Example:

long totalMessages = inbox.getMessageCount();
val totalMessages = inbox.getMessageCount()

getUnreadMessageCount

public long getUnreadMessageCount()

Total number of unread messages in inbox.

Example:

long unreadMessages = inbox.getUnreadMessageCount();
val unreadMessages = inbox.getUnreadMessageCount()

getAllMessages

public OpenBackAppInboxMessage[] getAllMessages()

Retrieve all Inbox messages. Messages are sorted by display time, from newest to oldest.

Example:

OpenBackAppInboxMessage[] messages = OpenBack.getAllMessages();
val messages = OpenBack.getAllMessages()

getReadMessages

public OpenBackAppInboxMessage[] getReadMessages()

Retrieve all Inbox read messages. Messages are sorted by display time, from newest to oldest.

Example:

OpenBackAppInboxMessage[] messages = OpenBack.getReadMessages();
val messages = OpenBack.getReadMessages()

getUnreadMessages

public OpenBackAppInboxMessage[] getUnreadMessages()

Retrieve all Inbox unread messages. Messages are sorted by display time, from newest to oldest.

Example:

OpenBackAppInboxMessage[] messages = OpenBack.getUnreadMessages();
val messages = OpenBack.getUnreadMessages()

markMessageAsRead

public boolean markMessageAsRead(OpenBackAppInboxMessage message)

Mark an Inbox message as read. Returns true if successful.

Example:

OpenBack.markMessageAsRead(message);
OpenBack.markMessageAsRead(message)

markMessagesAsRead

public boolean markMessagesAsRead(OpenBackAppInboxMessage[] messages)

Mark an Inbox messages as read. Returns true if successful.

Example:

OpenBack.markMessagesAsRead(messages);
OpenBack.markMessagesAsRead(messages)

markAllMessagesAsRead

public boolean markAllMessagesAsRead()

Mark an Inbox messages as read. Returns true if successful.

Example:

OpenBack.markAllMessagesAsRead();
OpenBack.markAllMessagesAsRead()

removeMessage

public boolean removeMessage(OpenBackAppInboxMessage message)

Remove message from the Inbox. Returns true if successful.

Example:

OpenBack.removeMessage(message);
OpenBack.removeMessage(message)

removeMessages

public boolean removeMessages(OpenBackAppInboxMessage[] messages)

Remove messages from the Inbox. Returns true if successful.

Example:

OpenBack.removeMessages(messages);
OpenBack.removeMessages(messages)

removeAllMessages

public boolean removeAllMessages()

Remove all message from the Inbox. Returns true if successful.

Example:

OpenBack.removeAllMessages();
OpenBack.removeAllMessages()

executeMessage

public boolean executeMessage(OpenBackAppInboxMessage message)

If a message is actionable, call this method to execute the associated action. Messages can have an actionable URL, deep-link, video, image, custom HTML. Executing a message will set the read status to true. Returns true if successful.

Example:

OpenBack.executeMessage(message);
OpenBack.executeMessage(message)

Handling Inbox Change Events

Starting with version 2.4.6 of the Android SDK, 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.

// The Intent Action
public final static String OPENBACK_APP_INBOX;

// The Intent Extra "event" types
public final static String APP_INBOX_MESSAGE_READ;
public final static String APP_INBOX_MESSAGE_ADDED;
public final static String APP_INBOX_MESSAGE_EXPIRED;

The intent contains 2 extra fields:

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

Example:

public class MyActivity extends AppCompatActivity {

    private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String event = intent.getStringExtra("event");
            long unread = intent.getLongExtra("unread", 0);
            switch (event) {
                case APP_INBOX_MESSAGE_ADDED:
                case APP_INBOX_MESSAGE_READ:
                case 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(mMessageReceiver, new IntentFilter(OPENBACK_APP_INBOX));
    }

    @Override
    protected void onDestroy() {
        LocalBroadcastManager.getInstance(getApplicationContext())
            .unregisterReceiver(mMessageReceiver);
        super.onDestroy();
    }
}

App Inbox Message

isActionable

public boolean isActionable()

Inbox message read status.

Example:

boolean isActionable = message.isActionable();
inbox.executeMessage(message);
val isActionable = message.isActionable()
inbox.executeMessage(message);

isRead

public boolean isRead()

Inbox message read status.

Example:

boolean isRead = message.isRead();
val isRead = message.isRead()

getDisplayTime

public long getDisplaytime()

Inbox message display time in seconds from UNIX epoch.

Example:

String content = message.getDisplaytime();
val content = message.getDisplaytime()

getTitle

public String getTitle()

Inbox message title.

Example:

String title = message.getTitle();
val title = message.getTitle()

getContent

public String getContent()

Inbox message content.

Example:

String content = message.getContent();
val content = message.getContent()

getPayload

public String getPayload()

Inbox message content custom payload.

Example:

String payload = message.getPayload();
val payload = message.getPayload()