Handling push notifications elegantly.

Push notifications help keep your customers up to date on information, but when the number of notifications is huge, the receivers may discard all the notifications together. This makes your customers miss important updates. In terms of providing the latest information to the customer, notifications with old information become obsolete and are to be discarded. 

A collapsible message is a message that may be replaced by a new message if it is yet to be seen or acted upon by the customer. Using the collapse key feature, you can overwrite the last update to the customer with a latest update. 

The following are some possible use-cases where a collapsible message is useful:

  • Increase your sales by updating your customers with up-to-date offer details.
  • Provide latest updates on election results.
  • Keep updating your customer with the latest information on the Weather updates.
  • Update sports fans with the latest scores.
  • Update the latest order status to your customers for a hassle-free delivery.

Platform-based implementation

APNS supports identifying multiple notifications into one single notification using the collapse identifier. Notifications with the same collapse identifier will only display the latest, and the older ones are discarded. This can be achieved by sending settings as part of the payload. 

Android does not support this feature, but app implementation can be customized to achieve this feature in Android. 

This blog provides the details of how it can be achieved in both the platforms.

Implement collapsing notifications in an iOS app

IBM Cloud Push Notifications supports this with the payload key apnsCollapseId. The following is a sample payload for sending a notification with the apnsCollapseId:

{
    "message":{
        "alert":"Build is successful "
    },
    "settings":{
        "apns":{
            "title":"new Status for the BuildId: #2345w",
           "apnsCollapseId":"CollapseId123"
        }
    }
}

This sample app displays the notifications on build status. Two notifications are sent to the iOS App about the status of a build with the same apnsCollapseId.  

Since the second notification also has the same apnsCollapseId and the user has not yet acted upon the notification, the old notification is replaced by the new one, and the user is displayed with only the new notification in the notification center. 

Implement collapsing notifications in an Android app

By default, Android does not support collapsing the notifications, but the same result can be achieved by custom implementation. 

Update the androidmanifest.xml file with the following. This helps override the Intent service:

<service android:exported="true" android:name=".MessageIntentServiceOne">
     <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT"/>
     </intent-filter>
</service>

This MessageIntentServiceOne is called when a new notification arrives for the app:

public class MessageIntentServiceOne extends MFPPushIntentService {

    @Override
    public void onMessageReceived(RemoteMessage message) {

        String from = message.getFrom();

        Map<String, String> data = message.getData();
        JSONObject dataPayload = new JSONObject(data);

        MFPInternalPushMessage recMessage = new MFPInternalPushMessage(dataPayload);
        int collapseid = -1;
        JSONObject payload = null;
        try {
            payload = new JSONObject(recMessage.getPayload());
            if(payload != null && payload.has("collapseId")) {
                collapseid = payload.getInt("collapseId");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if(collapseid != -1 ) {
            onNotificationReceived(data, collapseid);
        } else {
            super.onMessageReceived(message);
        }
    }
}

MessageIntentServiceOne.onMessageReceived is triggered when a new notification arrives. This method reads the collapseId from the payload, and based on the collapseId, replaces the old notification so that only the latest notification is displayed to the customer.

The following is a sample payload for sending a notification with the collapseId:

{ 
   "message":{ 
      "alert":"Build is successful "
   },
   "settings":{ 
      "apns":{ 
         "title":"new Status for the BuildId: #2345w",
         "apnsCollapseId":"CollapseId123"
      },
      "gcm":{ 
         "androidTitle":"new Status for the BuildId: #2345w",
         "payload":{ 
            "collapseId":"CollapseId123"
         }
      }
   }
}

Below are how the notifications are replaced in the Android notification center:

Note: collapseKey settings supported by IBM Cloud Push Notifications for Android are applied only for dozed notifications; normal notifications will not support this feature.

Resources

Categories

More from Announcements

IBM TechXchange underscores the importance of AI skilling and partner innovation

3 min read - Generative AI and large language models are poised to impact how we all access and use information. But as organizations race to adopt these new technologies for business, it requires a global ecosystem of partners with industry expertise to identify the right enterprise use-cases for AI and the technical skills to implement the technology. During TechXchange, IBM's premier technical learning event in Las Vegas last week, IBM Partner Plus members including our Strategic Partners, resellers, software vendors, distributors and service…

Introducing Inspiring Voices, a podcast exploring the impactful journeys of great leaders

< 1 min read - Learning about other people's careers, life challenges, and successes is a true source of inspiration that can impact our own ambitions as well as life and business choices in great ways. Brought to you by the Executive Search and Integration team at IBM, the Inspiring Voices podcast will showcase great leaders, taking you inside their personal stories about life, career choices and how to make an impact. In this first episode, host David Jones, Executive Search Lead at IBM, brings…

IBM watsonx Assistant and NICE CXone combine capabilities for a new chapter in CCaaS

5 min read - In an age of instant everything, ensuring a positive customer experience has become a top priority for enterprises. When one third of customers (32%) say they will walk away from a brand they love after just one bad experience (source: PWC), organizations are now applying massive investments to this experience, particularly with their live agents and contact centers.  For many enterprises, that investment includes modernizing their call centers by moving to cloud-based Contact Center as a Service (CCaaS) platforms. CCaaS solutions…

See what’s new in SingleStoreDB with IBM 8.0

3 min read - Despite decades of progress in database systems, builders have compromised on at least one of the following: speed, reliability, or ease. They have two options: one, they could get a document database that is fast and easy, but can’t be relied on for mission-critical transactional applications. Or two, they could rely on a cloud data warehouse that is easy to set up, but only allows lagging analytics. Even then, each solution lacks something, forcing builders to deploy other databases for…