Urbain Airship MessageCenter inbox messages always empty on Android

39 Views Asked by At

I'm implementing the Urbain Airship MessageCenter on my app and trying to display the messages list to the user.

The problem I am having is that MessageCenter.inbox.messages always returns an empty list, even though some test messages have been sent to the user (the user receives the push notifications and the messages snack bar is shown while the app is opened).

I tried calling airshipMessageCenter.inbox.fetchMessages() too, but the list remains empty.

Is there any special configuration that must be done on Android that I might be missing?

(The integration works perfectly on the iOS counterpart)

1

There are 1 best solutions below

0
Augusto Carmo On

Luckily, I've found out what I was missing to configure in code.

Analyzing the Inbox.java file, I saw that it had the following function in it:

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public void setEnabled(boolean isEnabled) {
    this.isEnabled.set(isEnabled);
}

While looking for where it was used, I found out that MessageCenter#updateInboxEnabledState uses it:

/**
 * Update the enabled state of the Inbox and initialize it if necessary.
 *
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
void updateInboxEnabledState() {
    boolean isEnabled = privacyManager.isEnabled(FEATURE_MESSAGE_CENTER);

    inbox.setEnabled(isEnabled);
    inbox.updateEnabledState();

    if (isEnabled) {
        if (!isStarted.getAndSet(true)) {
            UALog.v("Initializing Inbox...");

            pushManager.addInternalPushListener(pushListener);
        }
    } else {
        tearDown();
    }
}

Having that specific line in mind

boolean isEnabled = privacyManager.isEnabled(FEATURE_MESSAGE_CENTER);

I realized that all I had to do was to enable that feature while assembling my AirshipConfigOptions:

val builder = AirshipConfigOptions.newBuilder()

// ...

builder.setEnabledFeatures(
    // ...
    FEATURE_MESSAGE_CENTER
)