I have using awesome notification, Firebase messaging is used for push notification and in foreground notification is FirebaseMessaging.onMessage.listen
using this callback redirect the user to specific is working as expected
but when the app is closed and tap the background notification is not working and I have using this callback when the background notification received
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
is only opens the main screen not redirecting
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: int.parse(message.data["id"]),
channelKey: 'high_importance_channel',
title: message.data["title"],
body: message.data["body"],
icon: "resource://drawable/ic_stat_onesignal_default"),
actionButtons: [
NotificationActionButton(
key: 'MARK_DONE',
label: 'Snooze',
icon: "resource://drawable/ic_stat_onesignal_default",
enabled: true,
)
],
);
}
and my response from firebase messaging is
{id: 9352, body: body, title: title, click_action: FLUTTER_NOTIFICATION_CLICK}
<application
android:label="example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />
</application>
</manifest>
@pragma("vm:entry-point")
static Future<void> onActionReceivedMethod(
BuildContext context, ReceivedAction receivedAction) async {
ActionData actionData = ActionData(id: receivedAction.id.toString());
if (receivedAction.channelKey == 'high_importance_channel') {
Fluttertoast.showToast(msg: '${receivedAction.channelKey}');
}
Myapp.navigatorKey.currentState
?.pushReplacement(MaterialPageRoute(
builder: (_) => Home(
data: receivedAction.buttonKeyPressed,
)));
if (receivedAction.buttonKeyPressed == "") {
print("appointment");
Myapp.navigatorKey.currentState
?.pushReplacement(MaterialPageRoute(
builder: (context) =>Secondscreen
));
}