diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d212e874..b5b25a19c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ ## XX.XX.XX * The feedback widgets now have transparent backgrounds for a cleaner look. +* Extended the notification button URL handler to allow custom handling of URLs when notification buttons are clicked in the background. +* Added a config method to disable server config in the initialization "disableSDKBehaviorSettings()". * Deprecated "presentFeedbackWidget(widgetInfo, context, closeButtonText, devCallback)", replaced with "presentFeedbackWidget(widgetInfo, context, devCallback)" in the feedbacks. -* Added a config method to disable server config in the initialization "disableSDKBehaviorSettings()". ## 25.4.0 * ! Minor breaking change ! Removed Secure.ANDROID_ID usage in device id generation. The SDK now exclusively uses random UUIDs for device id generation. diff --git a/sdk/src/main/java/ly/count/android/sdk/Countly.java b/sdk/src/main/java/ly/count/android/sdk/Countly.java index 51e29aea3..15584c5a6 100644 --- a/sdk/src/main/java/ly/count/android/sdk/Countly.java +++ b/sdk/src/main/java/ly/count/android/sdk/Countly.java @@ -48,7 +48,6 @@ of this software and associated documentation files (the "Software"), to deal public class Countly { private final String DEFAULT_COUNTLY_SDK_VERSION_STRING = "25.4.1-RC2"; - /** * Used as request meta data on every request */ diff --git a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyNotificationButtonURLHandler.java b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyNotificationButtonURLHandler.java index d476de66d..c84dfe593 100644 --- a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyNotificationButtonURLHandler.java +++ b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyNotificationButtonURLHandler.java @@ -1,11 +1,14 @@ package ly.count.android.sdk.messaging; +import android.content.Context; + public interface CountlyNotificationButtonURLHandler { /** * Called when a notification button is clicked. * * @param url The URL associated with the button. + * @param context The context in which the button was clicked. * @return true if the URL was handled, false otherwise. */ - boolean onClick(String url); + boolean onClick(String url, Context context); } diff --git a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java index 65b3f994b..2d03ac989 100644 --- a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java +++ b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java @@ -61,7 +61,7 @@ public class CountlyPush { private static Application.ActivityLifecycleCallbacks callbacks = null; private static Activity activity = null; - private static CountlyConfigPush countlyConfigPush = null; + protected static CountlyConfigPush countlyConfigPush = null; static Integer notificationAccentColor = null; @@ -554,7 +554,7 @@ public void onClick(DialogInterface dialog, int which) { msg.recordAction(activity, 0); dialog.dismiss(); - if (countlyConfigPush.notificationButtonURLHandler != null && countlyConfigPush.notificationButtonURLHandler.onClick(msg.link().toString())) { + if (countlyConfigPush.notificationButtonURLHandler != null && countlyConfigPush.notificationButtonURLHandler.onClick(msg.link().toString(), activity)) { Countly.sharedInstance().L.d("[CountlyPush, displayDialog] Link handled by custom URL handler, skipping default link opening."); return; } @@ -601,9 +601,9 @@ private static void addButtons(final Context context, final AlertDialog.Builder @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); - + boolean isPositiveButtonPressed = (which == DialogInterface.BUTTON_POSITIVE); - if (countlyConfigPush.notificationButtonURLHandler != null && countlyConfigPush.notificationButtonURLHandler.onClick(msg.buttons().get(isPositiveButtonPressed ? 1 : 0).link().toString())) { + if (countlyConfigPush.notificationButtonURLHandler != null && countlyConfigPush.notificationButtonURLHandler.onClick(msg.buttons().get(isPositiveButtonPressed ? 1 : 0).link().toString(), context)) { Countly.sharedInstance().L.d("[CountlyPush, dialog button onClick] Link handled by custom URL handler, skipping default link opening."); return; } diff --git a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPushActivity.java b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPushActivity.java index fee2c46d0..3ae8f03d0 100644 --- a/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPushActivity.java +++ b/sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPushActivity.java @@ -160,6 +160,12 @@ private void performPushAction(Intent activityIntent) { try { if (message.link() != null) { Countly.sharedInstance().L.d("[CountlyPush, CountlyPushActivity] Starting activity with given link. Push body. [" + message.link() + "]"); + + if (CountlyPush.countlyConfigPush.notificationButtonURLHandler != null && CountlyPush.countlyConfigPush.notificationButtonURLHandler.onClick(message.link().toString(), context)) { + Countly.sharedInstance().L.d("[CountlyPush, CountlyPushActivity] Link handled by custom URL handler, skipping default link opening."); + return; + } + Intent i = new Intent(Intent.ACTION_VIEW, message.link()); i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | @@ -178,6 +184,11 @@ private void performPushAction(Intent activityIntent) { } } else { try { + if (CountlyPush.countlyConfigPush.notificationButtonURLHandler != null && CountlyPush.countlyConfigPush.notificationButtonURLHandler.onClick(message.buttons().get(index - 1).link().toString(), context)) { + Countly.sharedInstance().L.d("[CountlyPush, CountlyPushActivity] Link handled by custom URL handler, skipping default link opening."); + return; + } + Countly.sharedInstance().L.d("[CountlyPush, CountlyPushActivity] Starting activity with given button link. [" + (index - 1) + "] [" + message.buttons().get(index - 1).link() + "]"); Intent i = new Intent(Intent.ACTION_VIEW, message.buttons().get(index - 1).link()); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);