Using Inbox Service

Inbox Service is responsible for managing messages in the Inbox. The inbox is a simple one way delivery system that allows you to deliver messages to the user.

Note: Before using Inbox Service, you need to have a PowerAuthSDK object available and initialized with a valid activation. Without a valid PowerAuth activation, the service will return an error.

Inbox Service communicates with the Mobile Token API.

Creating an Instance

The preferred way of instantiating Operations Service is via WultraMobileToken class. See: Example Usage

Customized initialization

In case you need to create more customized instance. You can do so with an initializer.

val inboxService = InboxService(
    powerAuthSDK,
    appContext,
    httpClient,
    baseURL,
    tokenProvider,
    userAgent,
    gsonBuilder
)
  • powerAuthSDK - PowerAuthSDK instance
  • appContext - application context
  • httpClient - OkHttpClient with following SSLValidationStrategy
    • SSLValidationStrategy.default
    • SSLValidationStrategy.noValidation
    • SSLValidationStrategy.sslPinning
  • baseURL - address, where your operations server can be reached (ending with /enrollment-server in the default setup)

Optional parameters:

For these, if null is provided, default internal implementation is provided.

  • tokenProvider - Provider that provides a valid PowerAuth token from token store for api communication.
  • userAgent - Optional default user agent used for each request
  • gsonBuilder - Optional GSON builder for custom deserialization

Inbox Service Usage

Get Number of Unread Messages

To get the number of unread messages, use the following code:

inboxService.getUnreadCount { 
    it.onSuccess {
        if (it.countUnread > 0) {
            print("There are ${it.countUnread} new message(s) in your inbox")
        } else {
            print("Your inbox is empty")
        }
    }.onFailure {
        // Process error
    }
}

Get a List of Messages

The Inbox Service provide a paged list of messages:

// First page is 0, next 1, etc...
inboxService.getMessageList(pageNumber = 0, pageSize = 50, onlyUnread = false) {
    it.onSuccess { messages ->
        if (messages.count < 50) {
            // This is the last page
        }
        // Process messages    
    }.onFailure {
        // Process error
    }
}

To get the list of all messages, call:

inboxService.getAllMessages {
    it.onSuccess { messages ->
        print("Inbox contains the following message(s):")
        for (msg in messages) {
            print(" - ${msg.subject}")
            print("   * ID = ${msg.id}")
        }
    }.onFailure {
        // Process error
    }
}

Get Message Detail

Each message has its unique identifier. To get the body of the message, use the following code:

let messageId = messagesList.first!.id
inboxService.getMessageDetail(messageId) {
    it.onSuccess {
        print("Received message:")
        print("${it.subject}")
        print("${it.body}")
    }.onFailure {
        // Process error
    }
}

Set Message as Read

To mark the message as read by the user, use the following code:

let messageId = messagesList.first!.id
inboxService.markRead(messageId: messageId) {
    it.onSuccess {
        // OK
    }.onFailure {
        // Process error
    }
}

Alternatively, you can mark all messages as read:

inboxService.markAllRead {
    it.onSuccess {
        // OK
    }.onFailure {
        // Process error
    }
}

Error handling

Every error produced by the Inbox Service is of a WMTError type. For more information see detailed error handling documentation.

Last updated on Feb 13, 2025 (13:07) Edit on Github Send Feedback
Search

develop

Mobile Token SDK for Android