From 8fe0bd6039a941e10d755a0490a255fe6a53dc58 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Thu, 20 Aug 2020 14:50:17 +1000 Subject: [PATCH] [flutter_local_notifications] guard code getting intent from activity in case activity doesn't exist (#761) * add guard on getting intent from activity * revise changelog entry * revise changelog entry * fix changelog entry for 1.4.4+4 * fix grammar --- flutter_local_notifications/CHANGELOG.md | 4 ++++ .../FlutterLocalNotificationsPlugin.java | 8 +++----- flutter_local_notifications/pubspec.yaml | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/flutter_local_notifications/CHANGELOG.md b/flutter_local_notifications/CHANGELOG.md index c5702e340..ecf4c3dd4 100644 --- a/flutter_local_notifications/CHANGELOG.md +++ b/flutter_local_notifications/CHANGELOG.md @@ -1,3 +1,7 @@ +# [1.4.4+4] + +* [Android] Fix issue [759](https://github.com/MaikuB/flutter_local_notifications/issues/759) by guarding code on getting the intent from the activity in case there isn't an activity that could cause `initialize()` and `getNotificationAppLaunchDetails()` to fail when called from the background + # [1.4.4+3] * [Android] Fix issue [751](https://github.com/MaikuB/flutter_local_notifications/issues/751) where the `onSelectNotification` callback could be called again after the user has tapped on a notification, sent the application to the background and returned to the app via the Recents screen. This issue could have previously called `getNotificationAppLaunchDetails()` to mistakenly report that a notification launched the app when it's called again as part of the application being resumed diff --git a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java index 1dc02f7ec..9686576fb 100644 --- a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java +++ b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java @@ -832,8 +832,7 @@ private void show(MethodCall call, Result result) { private void getNotificationAppLaunchDetails(Result result) { Map notificationAppLaunchDetails = new HashMap<>(); String payload = null; - Intent intent = mainActivity.getIntent(); - Boolean notificationLaunchedApp = !initialized && mainActivity != null && SELECT_NOTIFICATION.equals(intent.getAction()) && !launchedActivityFromHistory(intent); + Boolean notificationLaunchedApp = !initialized && mainActivity != null && SELECT_NOTIFICATION.equals(mainActivity.getIntent().getAction()) && !launchedActivityFromHistory(mainActivity.getIntent()); notificationAppLaunchDetails.put(NOTIFICATION_LAUNCHED_APP, notificationLaunchedApp); if (notificationLaunchedApp) { payload = mainActivity.getIntent().getStringExtra(PAYLOAD); @@ -853,9 +852,8 @@ private void initialize(MethodCall call, Result result) { editor.putString(DEFAULT_ICON, defaultIcon); editor.commit(); - Intent intent = mainActivity.getIntent(); - if (mainActivity != null && !launchedActivityFromHistory(intent)) { - sendNotificationPayloadMessage(intent); + if (mainActivity != null && !launchedActivityFromHistory(mainActivity.getIntent())) { + sendNotificationPayloadMessage(mainActivity.getIntent()); } initialized = true; result.success(true); diff --git a/flutter_local_notifications/pubspec.yaml b/flutter_local_notifications/pubspec.yaml index cb3e6f286..6859eedde 100644 --- a/flutter_local_notifications/pubspec.yaml +++ b/flutter_local_notifications/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_local_notifications description: A cross platform plugin for displaying and scheduling local notifications for Flutter applications with the ability to customise for each platform. -version: 1.4.4+3 +version: 1.4.4+4 homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications dependencies: