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 287c32011a..7f122eb704 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java @@ -37,7 +37,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(); } 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 202de9d80e..dc7b34578d 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 @@ -50,10 +50,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; } /** @@ -246,7 +246,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);