Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_local_notifications] solves the expected behavior for 'didNotificationLaunchApp' #2150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public class FlutterLocalNotificationsPlugin
private static final String SELECT_FOREGROUND_NOTIFICATION_ACTION =
"SELECT_FOREGROUND_NOTIFICATION";
private static final String SCHEDULED_NOTIFICATIONS = "scheduled_notifications";
private static final String LAUNCHED_FROM_NOTIFICATION = "LAUNCHED_FROM_NOTIFICATION";
private static final String INITIALIZE_METHOD = "initialize";
private static final String GET_CALLBACK_HANDLE_METHOD = "getCallbackHandle";
private static final String ARE_NOTIFICATIONS_ENABLED_METHOD = "areNotificationsEnabled";
Expand Down Expand Up @@ -1580,21 +1581,38 @@ private void getNotificationAppLaunchDetails(Result result) {
Boolean notificationLaunchedApp = false;
if (mainActivity != null) {
Intent launchIntent = mainActivity.getIntent();

notificationLaunchedApp =
launchIntent != null
&& (SELECT_NOTIFICATION.equals(launchIntent.getAction())
|| SELECT_FOREGROUND_NOTIFICATION_ACTION.equals(launchIntent.getAction()))
&& !launchedActivityFromHistory(launchIntent);
isNotificationLaunchedApp(launchIntent);

if (notificationLaunchedApp) {
notificationAppLaunchDetails.put(
"notificationResponse", extractNotificationResponseMap(launchIntent));
launchIntent.putExtra(LAUNCHED_FROM_NOTIFICATION, true);
mainActivity.setIntent(launchIntent);
}
}

}
notificationAppLaunchDetails.put(NOTIFICATION_LAUNCHED_APP, notificationLaunchedApp);
result.success(notificationAppLaunchDetails);
}

private boolean isNotificationLaunchedApp(Intent launchIntent) {
Boolean isAlreadyLaunched = isAlreadyLaunched(launchIntent);
return launchIntent != null
&& (SELECT_NOTIFICATION.equals(launchIntent.getAction())
|| SELECT_FOREGROUND_NOTIFICATION_ACTION.equals(launchIntent.getAction()))
&& !launchedActivityFromHistory(launchIntent)
&& !isAlreadyLaunched;
}

private Boolean isAlreadyLaunched(Intent intent) {
if(intent != null && intent.hasExtra(LAUNCHED_FROM_NOTIFICATION)) {
return intent.getBooleanExtra(LAUNCHED_FROM_NOTIFICATION, false);
}
return false;
}

private void initialize(MethodCall call, Result result) {
Map<String, Object> arguments = call.arguments();
String defaultIcon = (String) arguments.get(DEFAULT_ICON);
Expand Down