-
Notifications
You must be signed in to change notification settings - Fork 17
Interactive notifications
Interactive notifications are push notifications that provide an option for end user to interact with application through button tap action. This interaction can be accomplished by using our predefined categories or creating your own.
Feature is provided since MM SDK version 1.6.16 but we recommend using 1.7.0 since we separated it to another module.
Each category has its own ID and actions with their IDs. mm_
prefix is reserved for all predefined IDs and cannot be used for custom actions. Actions may bring app to foreground or leave it in the background.
Starting in Android N, actions are shown without icons in order to accommodate more text. An icon should still be provided because devices with earlier versions of the OS continue to rely on it, as will Android Wear and Android Auto devices.
- Add dependency to
build.gradle
file. Interactive module requires core module library to be included, so following configuration should be the right one:
compile ('org.infobip.mobile.messaging.api:infobip-mobile-messaging-android-interactive-sdk:1.7.0@aar')
compile ('org.infobip.mobile.messaging.api:infobip-mobile-messaging-android-sdk:1.7.0@aar') {
transitive = true;
}
Check latest version here.
All required manifest components are merged to application manifest automatically by manifest merger. Please include interactive-related components to manifest manually if manifest merger was disabled.
- Subscribe to NOTIFICATION_ACTION_TAPPED event and you're all set up to test predefined categories. In the event you've subscribed to you can check which action has been chosen and act upon it:
// declare action tapped message receiver
private final BroadcastReceiver actionTappedMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Message message = Message.createFrom(intent.getExtras());
NotificationAction action = NotificationAction.createFrom(intent.getExtras());
NotificationCategory notificationCategory = NotificationCategory.createFrom(intent.getExtras());
if (action != null && "mm_accept".equals(action.getId()) {
// message.getCategory() should be the same as notificationCategory.getId()
// TODO
}
}
};
@Override
protected void onResume() {
super.onResume();
// subscribe to NOTIFICATION_ACTION_TAPPED event
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
localBroadcastManager.registerReceiver(actionTappedMessageReceiver, new IntentFilter(InteractiveEvent.NOTIFICATION_ACTION_TAPPED.getKey()));
}
- Use
setNotificationCategories
method to subscribe to custom categories
Interactive notifications can be tested through our Single PUSH message and Multiple PUSH messages APIs by using category
parameter.
With Mobile Messaging SDK you can send messages to arbitrary destinations from mobile device. These messages are also known as Mobile Originated (MO) messages. Actionable notifications are one of use-cases for the MO service, meaning that you can trigger outgoing MO message with any of notification actions. For instance, if user taps an "Vote" button, a specific MO message is sent to your backend service. In order to create a notification action that triggers MO messages, you should use withMoMessage
method of NotificationAction.Builder
:
NotificationAction voteAction = new NotificationAction.Builder()
.withId("vote")
.withTitleResourceId(R.string.vote)
.withIcon(R.drawable.vote)
.withMoMessage()
.build();
Mobile Messaging SDK provides one predefined interactive category for now, but this list will be extended.
Display of interactive notifications with predefined categories in notification center can be tested by including interactive module as described in the first step and sending message through Push API. Action handling needs to be implemented as described in the second step.
A = action
Category ID | Action ID | A - Title | A - Foreground | A - mo message |
---|---|---|---|---|
mm_accept_decline | mm_accept | Accept | true | true |
mm_decline | Decline | false | true |
Mobile Messaging SDK provides localization for action button titles of predefined categories. Titles are localized for the following languages: Arabic, Czech, Danish, German, English, Spanish (Latin America), Spanish, Finnish, French, Hebrew, Croatian, Hungarian, Indonesian, Italian, Japanese, Korean, Malay, Norwegian, Dutch, Polish, Portuguese (Portugal), Portuguese, Romanian, Russian, Slovak, Swedish, Thai, Turkish, Vietnamese, Chinese (Simplified), Chinese (Traditional), Hindi.
Setting up custom categories enables you to configure interactive notification categories along with their actions.
Maximum of three (3) actions are shown in the default notification layout. Actions are displayed in the order they've been set (in current example, "cancel" action will be on the left, "share" action will be on the right).
NotificationAction cancelAction = new NotificationAction.Builder()
.withId("cancel")
.withTitleResourceId(R.string.cancel)
.withIcon(R.drawable.cancel)
.withMoMessage()
.build();
NotificationAction shareAction = new NotificationAction.Builder()
.withId("share")
.withTitleResourceId(R.string.share)
.withIcon(R.drawable.share)
.withBringingAppToForeground(true)
.withMoMessage()
.build();
NotificationCategory notificationCategory = new NotificationCategory("category_share", cancelAction, shareAction);
MobileInteractive.getInstance(context).setNotificationCategories(notificationCategory);
The following screenshots demonstrate how our example interactive message is displayed on different android versions.
Android 4.4:
If you have any questions or suggestions, feel free to send an email to support@infobip.com or create an issue.
- Library events
- Server errors
- Users and installations
- Messages and notifications management
- Inbox
Geofencing API- DEPRECATED- Android Manifest components
- Privacy settings
- In-app chat
- Infobip RTC calls and UI
- Backup rules