Skip to content

Commit dbc8726

Browse files
authored
Merge pull request #478 from Countly/pn_callback_extend
feat: extended custom url handler PN
2 parents 4d01cc3 + ec8178e commit dbc8726

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## XX.XX.XX
22
* The feedback widgets now have transparent backgrounds for a cleaner look.
3+
* Extended the notification button URL handler to allow custom handling of URLs when notification buttons are clicked in the background.
4+
* Added a config method to disable server config in the initialization "disableSDKBehaviorSettings()".
35

46
* Deprecated "presentFeedbackWidget(widgetInfo, context, closeButtonText, devCallback)", replaced with "presentFeedbackWidget(widgetInfo, context, devCallback)" in the feedbacks.
5-
* Added a config method to disable server config in the initialization "disableSDKBehaviorSettings()".
67

78
## 25.4.0
89
* ! Minor breaking change ! Removed Secure.ANDROID_ID usage in device id generation. The SDK now exclusively uses random UUIDs for device id generation.

sdk/src/main/java/ly/count/android/sdk/Countly.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ of this software and associated documentation files (the "Software"), to deal
4848
public class Countly {
4949

5050
private final String DEFAULT_COUNTLY_SDK_VERSION_STRING = "25.4.1-RC2";
51-
5251
/**
5352
* Used as request meta data on every request
5453
*/
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package ly.count.android.sdk.messaging;
22

3+
import android.content.Context;
4+
35
public interface CountlyNotificationButtonURLHandler {
46
/**
57
* Called when a notification button is clicked.
68
*
79
* @param url The URL associated with the button.
10+
* @param context The context in which the button was clicked.
811
* @return true if the URL was handled, false otherwise.
912
*/
10-
boolean onClick(String url);
13+
boolean onClick(String url, Context context);
1114
}

sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPush.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class CountlyPush {
6161
private static Application.ActivityLifecycleCallbacks callbacks = null;
6262
private static Activity activity = null;
6363

64-
private static CountlyConfigPush countlyConfigPush = null;
64+
protected static CountlyConfigPush countlyConfigPush = null;
6565

6666
static Integer notificationAccentColor = null;
6767

@@ -554,7 +554,7 @@ public void onClick(DialogInterface dialog, int which) {
554554
msg.recordAction(activity, 0);
555555
dialog.dismiss();
556556

557-
if (countlyConfigPush.notificationButtonURLHandler != null && countlyConfigPush.notificationButtonURLHandler.onClick(msg.link().toString())) {
557+
if (countlyConfigPush.notificationButtonURLHandler != null && countlyConfigPush.notificationButtonURLHandler.onClick(msg.link().toString(), activity)) {
558558
Countly.sharedInstance().L.d("[CountlyPush, displayDialog] Link handled by custom URL handler, skipping default link opening.");
559559
return;
560560
}
@@ -601,9 +601,9 @@ private static void addButtons(final Context context, final AlertDialog.Builder
601601
@Override
602602
public void onClick(DialogInterface dialog, int which) {
603603
dialog.dismiss();
604-
604+
605605
boolean isPositiveButtonPressed = (which == DialogInterface.BUTTON_POSITIVE);
606-
if (countlyConfigPush.notificationButtonURLHandler != null && countlyConfigPush.notificationButtonURLHandler.onClick(msg.buttons().get(isPositiveButtonPressed ? 1 : 0).link().toString())) {
606+
if (countlyConfigPush.notificationButtonURLHandler != null && countlyConfigPush.notificationButtonURLHandler.onClick(msg.buttons().get(isPositiveButtonPressed ? 1 : 0).link().toString(), context)) {
607607
Countly.sharedInstance().L.d("[CountlyPush, dialog button onClick] Link handled by custom URL handler, skipping default link opening.");
608608
return;
609609
}

sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPushActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ private void performPushAction(Intent activityIntent) {
160160
try {
161161
if (message.link() != null) {
162162
Countly.sharedInstance().L.d("[CountlyPush, CountlyPushActivity] Starting activity with given link. Push body. [" + message.link() + "]");
163+
164+
if (CountlyPush.countlyConfigPush.notificationButtonURLHandler != null && CountlyPush.countlyConfigPush.notificationButtonURLHandler.onClick(message.link().toString(), context)) {
165+
Countly.sharedInstance().L.d("[CountlyPush, CountlyPushActivity] Link handled by custom URL handler, skipping default link opening.");
166+
return;
167+
}
168+
163169
Intent i = new Intent(Intent.ACTION_VIEW, message.link());
164170
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
165171
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |
@@ -178,6 +184,11 @@ private void performPushAction(Intent activityIntent) {
178184
}
179185
} else {
180186
try {
187+
if (CountlyPush.countlyConfigPush.notificationButtonURLHandler != null && CountlyPush.countlyConfigPush.notificationButtonURLHandler.onClick(message.buttons().get(index - 1).link().toString(), context)) {
188+
Countly.sharedInstance().L.d("[CountlyPush, CountlyPushActivity] Link handled by custom URL handler, skipping default link opening.");
189+
return;
190+
}
191+
181192
Countly.sharedInstance().L.d("[CountlyPush, CountlyPushActivity] Starting activity with given button link. [" + (index - 1) + "] [" + message.buttons().get(index - 1).link() + "]");
182193
Intent i = new Intent(Intent.ACTION_VIEW, message.buttons().get(index - 1).link());
183194
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

0 commit comments

Comments
 (0)