Android Inbox
If your application needs information about the push notifications that are previously sent to device by Netmera, you can use NetmeraInbox
class to fetch that information from Netmera.
The most common use case for this would be to show the list of notifications inside your application in an inbox-style interface.
NetmeraInbox
is the core class providing methods and properties needed for operations on push notifications like fetching push objects or updating push objects' status, but you can not directly initialize a NetmeraInbox
instance. You get an instance from SDK, then operate on that instance for future inbox actions. Here is the common workflow to use inbox feature of Netmera.
Determine properties of push notifications to fetch
You must first define filtering properties by creating a NetmeraInboxFilter
instance. You can determine which push notifications will be included in the fetched list by setting related properties of this NetmeraInboxFilter
instance.
NetmeraInboxFilter
class provides filtering according to the following options:
Inbox Status: Read / Unread / Deleted
Categories: Categories to which push notifications are belong.
Including expired push notifications or not.
Page Size: This is not to filter, but to determine the size of chunks which will be gathered during one request.
Here is a sample code to determine filtering options:
Fetch the first page and get the NetmeraInbox
instance
NetmeraInbox
instanceNow, you can request from Netmera to return the list of push notification objects matching with the filter object using the following code:
If fetch operations succeeds, NetmeraInbox.NetmeraInboxFetchCallback
's NetmeraInbox.NetmeraInboxFetchCallback
method will be called with an inbox
object which contains the first chunk of push notifications matching with given filter, and a null
error
. Otherwise, it will be called with a null
inbox
object and an error
object containing details about the reason of failure.
Now you can present the list of push objects inside your application. You get the list using pushObjects()
method of NetmeraInbox, which return a list of NetmeraPushObject
instances. Moreover, for further operations like fetching next pages, setting status, you will be using NetmeraInbox object's methods.
⚠️ Filter properties of an inbox instance could not be changed. If you need to modify filter properties, you have to create a new filter object and start a new fetch operation using
Netmera.fetchInbox
method.
Fetch next pages via NetmeraInbox object
After you get NetmeraInbox
object which contains first page of the push notifications, you can fetch next pages with a very similar code shown above but this time via your NetmeraInbox instance.
New pages are collected on already created NetmeraInbox
object, therefore you can use same response handling with fetching first page.
NetmeraInbox
has a method named hasNextPage
for checking whether there exists more pages or not. You can use that method to decide whether you should fetch next page or not, to change your ui to let user know she has got to the end of list, etc.
Here is the sample code:
⚠️ If you call fetchNextPage when there is no more next page, onFetchInbox method will be called immediately with a no next page error.
Update the status of push notifications
Push notifications may have 3 different states, which are the followings:
Unread
Read
Deleted
These three states allows you to implement a simple notification inbox interface for your users where they can read messages, mark previously read message as unread, delete messages and restore them again if needed.
You can make transitions among states for push notifications inside inbox using updateStatus
method. Calling this method will start an asynchronous request to update status for given push objects, and given callback will be called upon the result of the request.
Here is a sample implementation which deleted the first 5 push objects from inbox:
If operation fails for some reason, completion block will be called with a nonnull
error
parameter describing the reason of failure.
You can change the status of all the notifications in Inbox with a single method. You can call this method without calling the fetch / inbox method.
Get count for one or more status
You can get total count of push objects according to the status info among the push objects that matches given filter. Count can be get only for one specific status as well as for combined set of status values.
Message Category
In Netmera, we have a feature called Message Category. You may specify your categories in the Setting > Message Category page in the panel.
User Category Preferences:
To retrieve the user's category preferences, use the following method. It will return a list of category preferences, where each category preference data includes id, name, and enable status.
To manage the preference of a category and switch its status, use the following method. Provide the category ID and set the categoryEnabled parameter to either true
or false
.
These methods allow you to effectively fetch and manage category preferences for users in Netmera.
Last updated