Enable Mobile Messages for Android Devices

Notification Permissions for Android 13 and Above

Starting from Android 13, all applications must ask users for permissions to send push notification prompts. For more information, see Notification Permission for Opt-In Notifications.

  1. In your application's manifest file, declare the necessary notification permission. Here is an example:
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
  2. In your application's activity or fragment, request run-time permission from the user. Here is an example:
    String[] permissions = {Manifest.permission.POST_NOTIFICATIONS};
    
    activity.requestPermissions(permissions, MY_REQUEST_CODE);
    

Implement Firebase Cloud Messaging

For the Android platform, in-app messages and push notifications are delivered to devices through the Firebase Cloud Messaging (FCM) service. To use this service, you must register your application with Firebase and provide your Firebase Cloud Messaging API (V1) Key in JSON format to SAS Customer Intelligence 360. The mobile SDK uses the FCM service to push data to Android clients. This service balances battery performance with timely message delivery.

Note: When the user taps one of the buttons in an in-app message or opens a push notification, often the next best action is to navigate to a particular section of your app. Design your delegate to be as flexible as possible so that it can perform navigation based on the Uniform Resource Identifier (URI) link provided by the creative. The mobile SDK does not automatically open the app to the location specified by the URI. You must provide the necessary code for the app to carry out the desired action.

To implement Firebase Cloud Messaging in your app:

  1. To add Firebase to your Android project, follow the instructions from Firebase for Android and Firebase Cloud Messaging. Create an implementation of the FirebaseMessagingService interface and generate a key from the Firebase Developer Console.

    To generate a key, go to your project in the Firebase Developer Console > Project Settings > Cloud Messaging. Enable Firebase Cloud Messaging API (V1).

    This is enabled by default for all new FCM projects. However, if you have an older project and Firebase Cloud Messaging API (V1) is disabled, you can enable it by clicking on the three dots icon and selecting Manage API in Google Cloud Console. Click the Enable button. Navigate back to the Console screen. Firebase Cloud Messaging API (V1) should be enabled. Go to the Service Accounts tab and click Generate New Private Key.

    This generates a JSON file. Provide the entire JSON file to the SAS Customer Intelligence 360 user to use when they register the mobile app with SAS Customer Intelligence 360.

  2. In your implementation of the FirebaseMessagingService interface, when the onMessageReceived callback is made, pass the data member of the RemoteMessage to SASCollector.handleMobileMessage. If the call returns false, the message was not intended for the SASCollector and the app should process the call as necessary.
    if( ! SASCollector.getInstance().handleMobileMessage(remoteMessage.getData())) {
      //Handle non-SASCollector message
    }
    Note: The mobile SDK API, SASCollector.handleMobileMessage(Bundle), has been deprecated in favor of SASCollector.handleMobileMessage(Map String, String). The content of RemoteMessage.getData() no longer needs to be copied to a Bundle object.

    If you are initializing the SASCollector at a point other than the base application's onCreate path, the SASCollector should also be initialized in the onMessageReceived callback. Because the app might have been previously removed from memory, you must reassert any contingent logic to enable the SASCollector.

    When the onNewToken(String) callback is made, this token should be relayed to SAS Customer Intelligence 360 using the SASCollector.getInstance().registerForMobileMessages API.

    if (token != null) {
    
        SASCollector.getInstance().registerForMobileMessages(token, success -> {
            if (success) {
                SLog.d("TOKEN", "Registration success " + token);
    
    
            } else {
                SLog.d("TOKEN", "Registration failed ");
            }
        });
    
    }
    
  3. Relay the current FCM token to SAS Customer Intelligence 360 on each start-up of your application.
    String token = task.getResult();
    
    SASCollector.getInstance().registerForMobileMessages(token, success -> {
        if (success) {
            SLog.d("TOKEN", "Registration success " + token);
    
    
        } else {
            SLog.d("TOKEN", "Registration failed from settings ");
        }
    });
    
  4. Set the image resource to be used when displaying push notifications to the user.
    SASCollector.getInstance().setMobileMessagingIcon
    (R.drawable.my_notification_icon);

    By default, the mobile SDK uses the app's main icon. The icon is flattened to a single color. To specify a color for the icon, use this syntax:

    SASCollector.getInstance().setMobileMessagingIconColor(int color)
    Note: Only the transparency is preserved when the icon is rendered for a push notification. This transparency might make the app's main icon inappropriate for use in push notifications.
  5. Android 8 and later releases require that an application declare a channel when the application posts notifications. This must be executed before calling handleMobileMessage. Create a notification channel by using the NotificationManager API in the initialization of your application. After the SDK is initialized, use this syntax to pass the channel ID to the NotificationManager API:
    NotificationManager notificationManager =
         (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    
    NotificationChannel notificationChannel = new NotificationChannel(
         "<your notification channel name>",
         "Digital Marketing",
         NotificationManager.IMPORTANCE_HIGH
    );
    
    notificationManager.createNotificationChannel(notificationChannel);
    
    SASCollector.getInstance().setPushNotificationChannelId(notificationChannel.getId());
    Note: The name that you give the new NotificationChannel is displayed when you view the notification settings for the application via the Android user interface.

    If a notification channel has not been specified, the SDK attempts to use NotificationChannel.DEFAULT_CHANNEL_ID. This channel might not be available to applications that target API level 26 and later.

    For more information about Android notification channels, see https://developer.android.com/develop/ui/views/notifications/channels.

  6. (Optional) Set an implementation of SASMobileMessagingDelegate2 to receive callbacks regarding the user’s response to in-app messages and push notifications.
    SASCollector.getInstance().setMobileMessagingDelegate2(
      new SASMobileMessagingDelegate2() {
    
      @Override
      public void dismissed()  {
        //The user has dismissed an in-app message
      }
      
      @Override
      public void action(String link, SASMobileMessageType type) {
        
        // The type parameter is SASMobileMessageType.IN_APP_MESSAGE.
        // The user clicked one of the actions in the in-app message.
        // The String parameter is the notification URI that is specified
        // in the definition of the creative in SAS Customer Intelligence 
        // 360.
      }
    
      @Override
      public Intent getNotificationIntent(String link) {
    
        // The FCM message that is given to the mobile SDK contains a push 
        // notification.
        // The app must provide an Intent to handle if and when the user 
        // opens the notification.
        // The Intent must launch an Activity. 
        // The String parameter is the notification URI that is specified 
        // in the definition of the creative in SAS Customer Intelligence 
        // 360.
    
      
    
        // This is an example of how to send the link to your Activity.
    Intent intent = new Intent(myContext, LinkActivity.class); 
    
      intent.putExtra("my_link", link);
    
      return intent;
    
      }
    });
  7. (Optional) Call the unregisterForMobileMessages method below to unregister the mobile device token from SAS Customer Intelligence 360 and prevent applications from receiving remote notifications (for example, when logging out of the app). The device will be set to Unreachable in the SAS Customer Intelligence 360 Diagnostics page.
    IMPORTANT In order to resume receiving remote notifications, the mobile app developer will have to re-register the device token.
    SASCollector.getInstance().unregisterForMobileMessages(success -> {
        if (success) {
            SLog.d("TOKEN", "Device token deleted successfully");
        } else {
            SLog.d("TOKEN", "Device token deleted Failed.");
        }
    });
     
    

Default Behavior for Message Activity

The default behavior for when a user interacts with an in-app message or opens a push notification is as follows:

  • When the user taps one of the buttons in an in-app message, the message is closed. The system tracks that the user interacted with the in-app message.
  • When the user taps a push notification, the app is opened. The system tracks that the user tapped the push notification.

Often the desired behavior is for the message or notification to navigate to a particular section of your app. To do so, you will need to provide the necessary code for the delegate to handle links from the push notification or in-app message. The creative in the notification or message can contain a Uniform Resource Identifier (URI) link. If the delegate has the code to do so, it can open the location in the app specified by the URI.

Allow Push Notifications While Application is in Foreground

The default behavior for push notifications is that they do not appear on the device while the application is in use. The typical purpose of a push notification is to drive engagement to the application itself. However, there is support for push notifications while the app is in the foreground or in use.

To enable this option, create a key of allow.foreground.push.notifications set to a value of true in the SASCollector.properties file. Or, add a line of code to the app.

For example:

allow.foreground.push.notifications=true

or

SASCollector.getInstance().setAllowForegroundPushNotifications(true)
Last updated: August 11, 2026