From 3d6f175ae9b420240a2ba2b2451bd55a38f060cc Mon Sep 17 00:00:00 2001 From: Michael Oliveira <michael@luni.app> Date: Fri, 5 Jan 2024 14:42:04 +0100 Subject: [PATCH 1/2] Crash when the launch url is unknow -> catch and handle it on error listener --- .../src/main/java/com/onesignal/OneSignal.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java index 051f3ebf68..b32363694e 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java @@ -31,6 +31,7 @@ import android.app.AlertDialog; import android.app.Application; import android.app.NotificationManager; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; @@ -183,6 +184,13 @@ public interface OSNotificationOpenedHandler { void notificationOpened(OSNotificationOpenedResult result); } + /** + * Fires delegate when starting destination Activity fail. + */ + public interface OSNotificationOpenedError { + void onOpenDestinationActivityNotFoundError(ActivityNotFoundException exception); + } + /** * An interface used to process a OneSignal In-App Message the user just tapped on. * <br/> @@ -404,6 +412,7 @@ static Activity getCurrentActivity() { static OSRemoteNotificationReceivedHandler remoteNotificationReceivedHandler; static OSNotificationWillShowInForegroundHandler notificationWillShowInForegroundHandler; static OSNotificationOpenedHandler notificationOpenedHandler; + static OSNotificationOpenedError notificationOpenedError; static OSInAppMessageClickHandler inAppMessageClickHandler; // Is the init() of OneSignal SDK finished yet @@ -2459,8 +2468,14 @@ static void openDestinationActivity( } } catch (JSONException e) { e.printStackTrace(); + } catch (ActivityNotFoundException e) { + if (notificationOpenedError != null) { + notificationOpenedError.onOpenDestinationActivityNotFoundError(e); + } else { + e.printStackTrace(); + } } - } +} private static boolean shouldInitDirectSessionFromNotificationOpen(Activity context, final JSONArray data) { if (inForeground) { From 19a8f391afec93a626fe806d549fd3efe85fe89f Mon Sep 17 00:00:00 2001 From: Michael Oliveira <michael@luni.app> Date: Thu, 11 Jan 2024 14:34:03 +0100 Subject: [PATCH 2/2] Add setter for the NotificationOpenedError --- .../onesignal/src/main/java/com/onesignal/OneSignal.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java index b32363694e..ee7ad9c7ee 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java @@ -816,6 +816,10 @@ public static void setNotificationOpenedHandler(@Nullable OSNotificationOpenedHa fireCallbackForOpenedNotifications(); } + public static void setNotificationOpenedError(@Nullable OSNotificationOpenedError callback) { + notificationOpenedError = callback; + } + public static void setInAppMessageClickHandler(@Nullable OSInAppMessageClickHandler callback) { inAppMessageClickHandler = callback; }