NetmeraInbox allows you to access and manage previously sent push notifications in an inbox-style interface. You cannot instantiate NetmeraInbox directly; instead, you must obtain an instance through the SDK and use it to interact with push notifications.
Filtering Notifications
Create a NetmeraInboxFilter instance to specify which push notifications to fetch. You can filter by:
Status: Read, Unread, or Deleted.
Categories: Filter by specific categories.
Expired Notifications: Include or exclude expired notifications.
Page Size: Number of notifications to fetch per request.
Here is a sample code to determine filtering options:
Use Netmera.fetchInbox to retrieve notifications that match the filter:
Netmera.fetchInbox(filter, new NetmeraInbox.NetmeraInboxFetchCallback() {
@Override
public void onFetchInbox(NetmeraInbox netmeraInbox, NetmeraError error) {
if (error != null) {
// handle error
Toast.makeText(context, error.getMessage(), Toast.LENGTH_LONG).show();
return;
}
// Store returned inbox object for future operations
mInbox = netmeraInbox; // Store inbox object for future use
}
});
If successful, onFetchInbox will return an inbox object containing push notifications. Otherwise, it will return an error object with failure details.
Filter properties cannot be changed after fetching
To apply new filters, create a new filter object and fetch again:
// Create a new filter and fetch notifications again
NetmeraInboxFilter newFilter = new NetmeraInboxFilter.Builder()
.status(NetmeraPushObject.STATUS_UNREAD)
.build();
Netmera.fetchInbox(newFilter, callback);
Fetching Next Pages
Once the first page is retrieved, use mInbox.fetchNextPage() to get additional pages:
if (mInbox.hasNextPage()) {
mInbox.fetchNextPage(new NetmeraInbox.NetmeraInboxFetchCallback() {
@Override
public void onFetchInbox(NetmeraInbox netmeraInbox, NetmeraError error) {
// Handle response
}
});
}
Calling fetchNextPage() when no additional pages exist will trigger an error.
Updating Push Notification Status
Notifications can have three states:
Unread
Read
Deleted
Use updateStatus to change a notification's status asynchronously:
List<NetmeraPushObject> objectsToDelete = inbox.pushObjects().subList(0, 5);
inbox.updateStatus(objectsToDelete, NetmeraPushObject.STATUS_DELETED,
new NetmeraInbox.NetmeraInboxStatusCallback() {
@Override
public void onSetStatusInbox(NetmeraError error) {
if (error != null) {
// Handle error
}
}
});
You can also update the status of all notifications without fetching them:
public static void updateAll(@NetmeraPushObject.InboxStatus final int inboxStatus,
final NetmeraInbox.NetmeraInboxStatusCallback callback)