Push rich notifications to customers
This article provides information on how you can customize notifications that you push to your users.
Wait. Are you ready for this part?
In this article, we'll show you how to integrate notifications on your app with our platform so that we can send notifications to your app's users. However, this cannot work until you have the SDK in your project and you can use it in your app. If not, then we suggest that you do those things first and then come back here to integrate notifications on your app with our platform.
It's absolutely not complicated. We promise. And, like earlier, we'll wait. No pressure. βΊοΈ
Our Android SDK supports rich push notifications with contents like single image, animated carousel and non-animated carousel in addition to the basic notification content. If you could set up the SDK successfully, then we can push rich notifications to your customers who use your app without much of a problem.
Yes. It's kinda done. π And, you can create notifications in the rich push studio of our platform and send notifications to your app's users. Ensure that you follow the guidelines for the images that you want add in your notifications.
Push notification permission
If your application targets users with Android 13 and above devices, it is essential to request permission from the user to display notifications. The Blueshift Android SDK version 3.2.8-beta.1 and later includes a convenient helper method for this purpose. After presenting a rationale to the user for the consent, you can simply call this method to request for push notification permission.
Blueshift.requestPushNotificationPermission(context);
We also provide a feature where you could send an in-app notification to request notification permission. To know more about this, write to us at [email protected]
Push notification deep links
Blueshift lets you add deep links to the push notifications. The deep links can be associated with push notifications as well as the images we use in them (when using carousel push notifications). When clicking these elements, Blueshift SDK will open the host application and deliver the deep link URL to its LAUNCHER activity inside its Bundle. You may use the following code to read it within your activity.
String deepLinkURL = getIntent().getStringExtra(RichPushConstants.EXTRA_DEEP_LINK_URL);
Advanced customizations
The Blueshift SDK is specifically designed to efficiently handle a wide range of use cases related to push notifications using FCM (Firebase Cloud Messaging). However, we understand that you may have unique requirements that necessitate modifying the way the Blueshift SDK manages notifications. In the following sections, we will provide you with examples of how to override the current push notification implementation, allowing you to customize it to suit your specific needs.
Use existing Firebase Messaging Service
The Blueshift SDK provides the BlueshiftMessagingService
class, designed to handle push notifications sent from the Blueshift dashboard. However, if your app already utilizes an existing FirebaseMessagingService
implementation, it may be more suitable to leverage that instead of redirecting all push notifications, including non-Blueshift messages, to BlueshiftMessagingService
.
To ensure a smooth integration, we offer helper methods specifically tailored to handle Blueshift push notifications. These methods can be invoked from your FirebaseMessagingService
implementation. For further details and implementation guidance, please refer to the following code snippet.
class ExistingMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (BlueshiftUtils.isBlueshiftPushMessage(remoteMessage)) {
BlueshiftMessagingService.handleMessageReceived(applicationContext, remoteMessage)
} else {
// The push message does not belong to Blueshift. Please handle it here.
}
}
override fun onNewToken(newToken: String) {
// for SDK version v4.0.0 and above
BlueshiftMessagingService.handleNewToken(applicationContext, newToken)
// for SDK version older than v4.0.0
BlueshiftMessagingService.handleNewToken(newToken)
// Use the new token in your app if needed.
}
}
public class ExistingMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (BlueshiftUtils.isBlueshiftPushMessage(remoteMessage)) {
BlueshiftMessagingService.handleMessageReceived(getApplicationContext(), remoteMessage);
} else {
// The push message does not belong to Blueshift. Please handle it here.
}
}
@Override
public void onNewToken(String newToken) {
// for SDK version v4.0.0 and above
BlueshiftMessagingService.handleNewToken(getApplicationContext(), newToken);
// for SDK version older than v4.0.0
BlueshiftMessagingService.handleNewToken(newToken);
// Use the new token in your app if needed.
}
}
By utilizing these helper methods, you can effectively manage Blueshift push notifications while seamlessly integrating them into your existing Firebase messaging service implementation.
Overriding the push notification clicks
When you click on push notifications sent from Blueshift, the SDK starts an activity called BlueshiftNotificationEventsActivity
. This activity is in charge of handling what happens when you click on the notification. It does two main things: it sends a message to Blueshift saying that you clicked on the notification, and it handles the deep link associated with the notification.
However, sometimes the app you're using might have some unique situations where it needs to do something different when you click on the notification. In those cases, the app can change or override the default behavior of the SDK. The following code shows an example of how the app can take control and change what happens when you click on a push notification that comes from the SDK.
Step 1: Add a new activity to the app and make it extend the BlueshiftNotificationEventsActivity
class.
class CustomNotificationEventsActivity : BlueshiftNotificationEventsActivity() {
override fun processAction(action: String?, extraBundle: Bundle?) {
super.processAction(action, extraBundle)
// Do the app specific actions here.
}
}
public class CustomNotificationEventsActivity extends BlueshiftNotificationEventsActivity {
@Override
protected void processAction(String action, Bundle extraBundle) {
super.processAction(action, extraBundle);
// Do the app specific actions here.
}
}
To ensure that the clicks are properly registered, it's important to include the line
super.processAction(action, extraBundle);
in the above code. Without this line, the clicks won't be registered.If you want to completely bypass the default code executed by the SDK by removing the above line, you'll need to manually trigger the click events to Blueshift.
Step 2: Register the newly added activity in the AndroidManifest.xml
<activity
android:name=".advanced.CustomNotificationEventsActivity"
android:exported="false">
<intent-filter>
<action android:name="com.blueshift.NOTIFICATION_CLICK_EVENT" />
</intent-filter>
</activity>
Listen to the push notification events
Min SDK version 3.1.9
If you want to track the delivery and click events of push messages from outside the Blueshift SDKs, you can set listeners to receive callbacks for these events. This allows you to stay informed when a push message is delivered or clicked on.
The push notification payload will be passed in as a Map object in both callbacks.
Blueshift.setBlueshiftPushListener(object : BlueshiftPushListener {
override fun onPushDelivered(map: Map<String, Any>) {
Log.d(TAG, "onPushDelivered:")
}
override fun onPushClicked(map: Map<String, Any>) {
Log.d(TAG, "onPushClicked:")
}
})
Blueshift.setBlueshiftPushListener(new BlueshiftPushListener() {
@Override
public void onPushDelivered(Map<String, Object> map) {
Log.d(TAG, "onPushDelivered:");
}
@Override
public void onPushClicked(Map<String, Object> map) {
Log.d(TAG, "onPushClicked:");
}
});
Schedule push notifications
The Schedule Push Notification feature lets you schedule the timing of push notifications separately from when the campaign is executed. This feature gives marketers the ability to set a specific time for push notifications to appear on users' phones. For example, you can run a campaign at 5 am and have the push notification displayed to users at 9 am.
How to Use This
To get started, make sure you have upgraded your Android app to use the latest release of the SDK (version 1.1.3 or higher). Then, follow these steps:
- Create a push notification using the custom JSON option in the Push Studio.
- Associate the push notification template with a campaign.
Payload
In the payload of the push notification, you'll need to include these two additional fields:
{
"timestamp_to_display": 1508142900, // epoch timestamp
"timestamp_to_expire_display": 1510820700, // <optional> epoch timestamp
}
timestamp_to_display
: This specifies the time when the push message should be displayed. If a push message is received after this timestamp and is still valid, it will be displayed immediately.
timestamp_to_expire_display
: If the push message is received later than this timestamp, it will not be displayed.
By providing these timestamps, you can control when the push notification appears on users' devices, ensuring timely delivery and relevance.
For any questions related to the payload, please contact us at: [email protected]
Updated 3 months ago