diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java index b015711dff..24a44167f7 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java @@ -39,7 +39,7 @@ public LocalNotifications() { public void load() { super.load(); notificationStorage = new NotificationStorage(getContext()); - manager = new LocalNotificationManager(notificationStorage, getActivity()); + manager = new LocalNotificationManager(notificationStorage, getActivity(), getContext()); manager.createNotificationChannel(); notificationChannelManager = new NotificationChannelManager(getActivity()); } diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java index b903377374..2a8f60c256 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/notification/LocalNotificationManager.java @@ -51,10 +51,10 @@ public class LocalNotificationManager { private Activity activity; private NotificationStorage storage; - public LocalNotificationManager(NotificationStorage notificationStorage, Activity activity) { + public LocalNotificationManager(NotificationStorage notificationStorage, Activity activity, Context context ) { storage = notificationStorage; this.activity = activity; - this.context = activity; + this.context = context; } /** @@ -260,7 +260,13 @@ private void createActionIntents(LocalNotification localNotification, Notificati @NonNull private Intent buildIntent(LocalNotification localNotification, String action) { - Intent intent = new Intent(context, activity.getClass()); + Intent intent; + if (activity != null) { + intent = new Intent(context, activity.getClass()); + } else { + String packageName = context.getPackageName(); + intent = context.getPackageManager().getLaunchIntentForPackage(packageName); + } intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);