API Reference

extensionVersion

Returns the library version.
Android
iOS

Java

Syntax

1
public static String extensionVersion();
Copied!

Example

1
Messaging.extensionVersion();
Copied!

Swift

Syntax

1
public static let extensionVersion
Copied!

Example

1
Messaging.extensionVersion
Copied!

Objective-C

Syntax

1
public static let extensionVersion
Copied!

Example

1
[AEPMobileMessaging extensionVersion];
Copied!

handleNotificationResponse

Transmits the push notification interactions feedback.
Android
iOS

Java

Syntax

1
public static void handleNotificationResponse(final Intent intent, final boolean applicationOpened, final String customActionId);
Copied!
    intent - Intent which contains information related to messageId and data.
    applicationOpened - boolean values denoting whether the application was opened or not.
    actionId - String values denoting the id of the custom action.

Example

1
// Intent can be retrieved from the Activity/BroadcastReceiver using the getIntent() method.
2
Intent intent = getIntent();
3
Messaging.handleNotificationResponse(intent, true, "customActionId");
Copied!

Swift

Syntax

1
static func handleNotificationResponse(_ response: UNNotificationResponse, applicationOpened: Bool, customActionId: String?)
Copied!
    response - UNNotificationResponse response object containing push notification details
    applicationOpened - Bool values denoting whether the application was opened or not.
    customActionId - Option String values denoting the id of the custom action.

Example

1
func userNotificationCenter(_: UNUserNotificationCenter,
2
didReceive response: UNNotificationResponse,
3
withCompletionHandler completionHandler: @escaping () -> Void) {
4
Messaging.handleNotificationResponse(response, applicationOpened: true, customActionId: "customActionId")
5
completionHandler()
6
}
Copied!

Objective-C

Syntax

1
@objc(handleNotificationResponse:applicationOpened:withCustomActionId:)
2
static func handleNotificationResponse(_ response: UNNotificationResponse, applicationOpened: Bool, customActionId: String?)
Copied!

Example

1
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
2
didReceiveNotificationResponse:(UNNotificationResponse *)response
3
withCompletionHandler:(void (^)())completionHandler {
4
// Your code
5
[AEPMobileMessaging handleNotificationResponse:response applicationOpened:true withCustomActionId:@"customActionId"]
6
completionHandler();
7
}
Copied!

registerExtension

Registers the extension with the Mobile Core.
Android
iOS

Java

Syntax

1
public static void registerExtension();
Copied!

Example

1
Messaging.registerExtension();
Copied!

Swift

Use the MobileCore API to register the Messaging extension.

Syntax

1
public static func registerExtensions(_ extensions: [NSObject.Type], _ completion: (() -> Void)? = nil)
Copied!

Example

1
MobileCore.registerExtensions([Messaging.self, ...], {
2
// processing after registration
3
})
Copied!

Objective-C

Use the AEPMobileCore API to register the Messaging extension.

Syntax

1
public static func registerExtensions(_ extensions: [NSObject.Type], _ completion: (() -> Void)? = nil)
Copied!

Example

1
[AEPMobileCore registerExtensions:@[AEPMobileMessaging.class, ...] completion:^{
2
// processing after registration
3
}];
Copied!

setPushIdentifier

Although this API is provided in Mobile Core, the use of this API is required and leveraged by the Adobe Journey Optimizer extension to sync provided push tokens with Adobe Experience Platform services.
Android
iOS
To retrieve the push token from Firebase Messaging Service follow this Firebase documentation. After retrieving the push token use the below core API to sync it with profile in platform.

Java

Syntax

1
public static void setPushIdentifier(final String pushIdentifier);
Copied!
    pushIdentifier - A String value denoting the push token.

Examples

1
FirebaseMessaging.getInstance().getToken()
2
.addOnCompleteListener(new OnCompleteListener<String>() {
3
@Override
4
public void onComplete(@NonNull Task<String> task) {
5
if (task.isSuccessful()) {
6
String token = task.getResult();
7
MobileCore.setPushIdentifier(token);
8
}
9
}
10
});
Copied!

Swift

To retrieve the push token in iOS, checkout the apple documentation Apple's documentation. After retrieving the push token use the below core API to sync it with profile in platform.

Syntax

1
public static func setPushIdentifier(_ deviceToken: Data?)
Copied!
    deviceToken - A Data value denoting the push token.

Examples

1
func application(_: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
2
MobileCore.setPushIdentifier(deviceToken)
3
}
Copied!

Objective-C

Syntax

1
public static func setPushIdentifier(_ deviceToken: Data?)
Copied!
    deviceToken - A Data value denoting the push token.

Examples

1
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
2
[AEPMobileCore setPushIdentifier:deviceToken];
3
}
Copied!

addPushTrackingDetails

This API is used to updated the push notification pending intent with necessary customer journey information.
Call to this API is necessary to ensure that all the important information (messageId, Customer journey information) are added to the pending intent so that they can be used while tracking the push notification interactions.
Android

Java

Syntax

1
public static boolean addPushTrackingDetails(final Intent intent, final String messageId, final Map<String, String> data)
Copied!
    intent - Intent which is added to the pending intent so that it can be used when user interacts with the notification.
    messageId - String message ID of the push notification
    data - Map which represents the data part of the remoteMessage.
    Returns boolean indicating whether the intent was updated with necessary information (messageId and customer journey data).

Examples

1
boolean success = addPushTrackingDetails(intent, messageId, data)
Copied!

Public Classes

MessagingPushPayload

This is a helper class for extracting the data payload attributes from RemoteMessage which are used while creating the push notification. Create the instance of MessagingPushPayload in the onMessageReceived method using the below constructors.

Constructor

Android

Java

Syntax

1
public MessagingPushPayload(RemoteMessage message)
Copied!
    message - RemoteMessage message containing the payload data with the necessary attributes for creating push notification
1
public MessagingPushPayload(Map<String, String> data)
Copied!
    data - Map<String, String> data payload containing the necessary attributes for creating push notification

Examples

1
// Using the remote message
2
@Override
3
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
4
MessagingPushPayload payload = new MessagingPushPayload(remoteMessage);
5
}
6
7
// Using the data map
8
@Override
9
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
10
MessagingPushPayload payload = new MessagingPushPayload(remoteMessage.getData());
11
}
Copied!

Public APIs

Public APIs for getting attributes from push payload which are used while creating the push notification.
Android

Java

Syntax

1
// Returns the title from the remote message
2
public String getTitle()
3
4
// Returns the body from the remote message
5
public String getBody()
6
7
// Returns the sound from the remote message
8
// The sound string represents the filename of a sound resource bundled in the app.
9
public String getSound()
10
11
// Returns the notification badge count from the remote message
12
public int getBadgeCount()
13
14
// Returns the notification priority from the remote message.
15
// Check out the firebase documentation here (https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notificationpriority)
16
public int getNotificationPriority()
17
18
// Returns the channel Id from the remote message.
19
public String getChannelId()
20
21
// Returns the icon string from the remote message.
22
// The icon string represents the drawable resource name in the app.
23
public String getIcon()
24
25
// Returns the image url from the remote message.
26
// The icon string represents the drawable resource name in the app.
27
public String getImageUrl()
28
29
// Returns the data map from the remote message.
30
public Map<String, String> getData()
31
32
// Returns an ActionType object which represents the type of action which needs to be performed on push notification interaction.
33
// Check the ActionType enum definition below.
34
public ActionType getActionType()
35
36
// Returns a String action uri which is used to direct the push notification interaction.
37
public String getActionUri()
38
39
// Returns a list of ActionButtons. Check the ActionButtons class definition below
40
public List<ActionButton> getActionButtons()
Copied!
Internal Classes and Enums
ActionType
1
public enum ActionType {
2
DEEPLINK, WEBURL, DISMISS, NONE
3
}
Copied!
ActionButtons
1
// Constructor
2
public ActionButton(final String label, final String link, final String type)
3
4
// Public APIs
5
6
// Returns the label for the action button
7
public String getLabel()
8
9
// Returns the link for the action button
10
public String getLink()
11
12
// Returns the ActionType for the action button
13
public ActionType getType()
Copied!

Payload Keys

Description of Push Notification payload keys
iOS
Android
1
{
2
"aps":{
3
"alert":{
4
"title":"Hello from CJM",
5
"body":"Stay safe, wear mask"
6
},
7
"sound":"dingDong",
8
"badge":2,
9
"mutable-content":1,
10
"category":"iosCategory",
11
"thread-id":"myGroup",
12
"content-available":1
13
},
14
"a":"x",
15
"b":"y",
16
"adb_media":"www.imageUrl.com",
17
"adb_a_type":"DEEPLINK/WEBURL/DISMISS",
18
"adb_uri":"deeplink://url / weburl",
19
"adb_act":[
20
{
21
"aid":"customId1",
22
"label":"dismiss",
23
"type":"DISMISS"
24
}
25
]
26
}
Copied!
Key
Description
adb_media
URL of the rich media like image/video/gif. This url can be used to download the rich media before showing the push notification.
adb_uri
Web URL / Deeplink URI - Used to open appropriate webpage/app screen when notification is clicked.
adb_a_type
Can be one of the following string DEEPLINK / WEBURL / DISMISS. Used to determine what type of action to be performed when notification is clicked.
adb_act
Array containing the Action json object.
aid
Part of action object denoting the action ID
label
Part of action object denoting the action name
type
Part of action object denoting the action type. Can have one of the following value DEEPLINK / WEBURL / DISMISS
We recommend you use the MessagingPushPayload class for extracting the payload values.
1
{
2
"message":{
3
"android":{
4
"collapse_key": "new_message",
5
"priority": "HIGH",
6
"data":{
7
"adb_title":"Game Request",
8
"adb_body":"Bob wants to play poker",
9
"adb_sound" : "somesound_res",
10
"adb_n_count" : "3",
11
"." : "PRIORITY_LOW",
12
"adb_channel_id": "cid",
13
"adb_icon" : "notification_icon",
14
"adb_image": "www.imageUrl.com",
15
"adb_a_type": "DEEPLINK/WEBURL/DISMISS",
16
"adb_uri" : "uri/weburl",
17
"adb_act" : "[\n {\n \"label\" : \"deeplink\",\n \"uri\" : \"notificationapp://\",\n \"type\" : \"DEEPLINK\"\n },\n {\n \"label\" : \"weburl\",\n \"uri\" : \"https://www.yahoo.com\",\n \"type\" : \"WEBURL\"\n},\n{\n\"label\" : \"dismiss\",\n\"uri\" : \"\",\n \"type\" : \"DISMISS\"\n}\n]",
18
"some_custom_data_key": "some data"
19
}
20
}
21
}
22
}
Copied!
Key
Description
adb_title
String value denoting the push notification title
adb_body
String value denoting the push notification body
adb_sound
String value denoting the push notification sound
adb_n_count
String value denoting the push notification badge count
adb_n_priority
String value denoting the push notification priority Check firebase documentation
adb_channel_id
String value denoting the push notification channel id
adb_icon
String value denoting the push notification icon resource name
adb_image
URL of the image to be displayed on the notification
adb_a_type
Can be one of the following string DEEPLINK / WEBURL / DISMISS. Used to determine what type of action to be performed when notification is clicked.
adb_uri
Web URL / Deeplink URI - Used to open appropriate webpage/app screen when notification is clicked.
adb_act
String value denoting the action objects with label, uri and type.
label
Part of adb_act string denoting the action type.
uri
Part of adb_act string denoting the uri of the action
type
Part of adb_act string denoting the action type. Can have one of the following value DEEPLINK / WEBURL / DISMISS
Last modified 1mo ago