flutter_local_notifications
flutter_local_notifications copied to clipboard
onDidReceiveNotificationResponse not working (Android)
`@pragma('vm:entry-point')
void onDidReceiveNotificationResponse( NotificationResponse notificationResponse) async { final prefs = await SharedPreferences.getInstance(); final String? payload = notificationResponse.payload; if (notificationResponse.payload != null) { debugPrint('notification payload: $payload'); } }`
`Future
const initializationSettingsAndroid = AndroidInitializationSettings('app_icon6'); const InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid); flutterLocalNotificationsPlugin.initialize(initializationSettings, onDidReceiveNotificationResponse: onDidReceiveNotificationResponse); final NotificationAppLaunchDetails? notificationAppLaunchDetails = await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails(); String? payload = notificationAppLaunchDetails!.notificationResponse?.payload; }`
AndroidManifest:
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" /> <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/> </intent-filter> </receiver> <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" /> .... <service android:name="com.dexterous.flutterlocalnotifications.ForegroundService" android:exported="false" android:stopWithTask="false"/>