clevertap-react-native
clevertap-react-native copied to clipboard
How to perform the notification actions without app launch.
I have implemented actions for the android notification successfully. But I did not find any documentation about how to perform the action without launching the app.
Is it possible to perform the actions without launching the app?
@mouricef Didn't get your question. Please explain in detail.
@piyush-kukadiya
We are trying to implement the actions in the push notification on android. We can send the push notification with actions but not sure on how to handle the action click.
Below is our use case,
Send the push notification with some title and message where user can perform the CTA such as like or dislike for example. After user click on the notification actions, we want to perform the API call without launching the app. We went through the documentation but was not able to find the proper details on how to implement this. Can someone from your team help us to integrate this feature in our app.
After exploring the clevertap android sdk code. We are able to achieve this using Intent service like this,
<service android:name=".notification.NotificationCTAService" android:label="" android:exported="false">
<intent-filter>
<action android:name="com.clevertap.PUSH_EVENT" />
</intent-filter>
</service>
When an action button of a clevertap notification in my app is clicked then above intent service is started. But this only works for android 11 and below but for android 12 and above action always launch the application.
After checking the sdk code we found that notification actions are set using below method from INotificationRenderer interface (com.clevertap.android.sdk.pushnotification)
default NotificationCompat.Builder setActionButtons( Context context, Bundle extras, int notificationId, NotificationCompat.Builder nb, JSONArray actions )
This method check for different condition to decide whether to call intent service or activity. Because we are not using any push template this condition always return false for "sendToCTIntentService" on android 12 and above.
boolean sendToCTIntentService = (VERSION.SDK_INT < VERSION_CODES.S && autoCancel
&& isCTIntentServiceAvailable);
String dismissOnClick = extras.getString("pt_dismiss_on_click");
/**
* Send to CTIntentService in case (OS >= S) and notif is for Push templates with remind action
*/
if (!sendToCTIntentService && PushNotificationHandler.isForPushTemplates(extras)
&& id.contains("remind") && dismissOnClick!=null &&
dismissOnClick.equalsIgnoreCase("true") && autoCancel &&
isCTIntentServiceAvailable) {
sendToCTIntentService = true;
}
/**
* Send to CTIntentService in case (OS >= S) and notif is for Push templates with pt_dismiss_on_click
* true
*/
if (!sendToCTIntentService && PushNotificationHandler.isForPushTemplates(extras)
&& dismissOnClick!=null && dismissOnClick.equalsIgnoreCase("true")
&& autoCancel && isCTIntentServiceAvailable) {
sendToCTIntentService = true;
}
PushNotificationHandler.isForPushTemplates(extras) check from last condition is causing the issue. Otherwise sendToCTIntentService would have been true and intent service might be used in that case.
Any specific reason to allow intent service for push template only on android 12 and above?
@mouricef Due to notification trampoline we added this check. We will discuss this internally if we can provide CTA callback to Apps and let you know. Thanks!