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

Notifications still getting duplicated in forground #4

Open
rashmiranjanrrs opened this issue Apr 4, 2023 · 13 comments
Open

Notifications still getting duplicated in forground #4

rashmiranjanrrs opened this issue Apr 4, 2023 · 13 comments

Comments

@rashmiranjanrrs
Copy link

PLEASE HELP ITS URGENT

  • In your new branch also the duplication issue there and also there is only getter functions so how to set notification, channel id and all otherthings please let me know. Urgent....!!
  • Also in foreground ontap is working but in background its not working.
    `
    signal-2023-04-04-104339

firebase_notifications_handler:
git:
url: https://github.com/rithik-dev/firebase_notifications_handler.git
ref: df127ad
`

@rithik-dev
Copy link
Owner

Hey, @rashmiranjanrrs, Can you share the logs that you get when you receive the notification?

I did not face these issues recently, not sure why this is happening.

If you want a quick workaround though, for the duplicate notifications, the shouldHandleNotification param is there. You can probably maintain a state variable containing the title and body and check whether to show the notification or not.

For the onTap, which was working in all scenarios I tested, can you share what was the app state when you received the notification, and what was the state when you clicked it?

Also, to pass channelId and etc. things, for android, there is a param androidConfig, pass an object of AndroidNotificationsConfig, which has a getter for channel id, which you can pass like:

androidConfig: AndroidNotificationsConfig(
        channelIdGetter: (msg) => msg.notification?.android?.channelId ?? 'default',
),

You just have to set this param, the rest is handled internally...

@rashmiranjanrrs
Copy link
Author

Hey, @rashmiranjanrrs, Can you share the logs that you get when you receive the notification?

I did not face these issues recently, not sure why this is happening.

If you want a quick workaround though, for the duplicate notifications, the shouldHandleNotification param is there. You can probably maintain a state variable containing the title and body and check whether to show the notification or not.

For the onTap, which was working in all scenarios I tested, can you share what was the app state when you received the notification, and what was the state when you clicked it?

Also, to pass channelId and etc. things, for android, there is a param androidConfig, pass an object of AndroidNotificationsConfig, which has a getter for channel id, which you can pass like:

androidConfig: AndroidNotificationsConfig(
        channelIdGetter: (msg) => msg.notification?.android?.channelId ?? 'default',
),

You just have to set this param, the rest is handled internally...

I will test it with setting up the channel Id but Will the ontap function will work for both foreground and background?

@rithik-dev
Copy link
Owner

Yes, the onTap works for every possible scenario.

@rashmiranjanrrs
Copy link
Author

For icon should I do the same like this bellow?
iconGetter: (msg) => "@drawable/notification_icon"

@rashmiranjanrrs
Copy link
Author

 return FirebaseNotificationsHandler(
      onFcmTokenInitialize: (token) {
        print('token $token');
       
      },
      onFcmTokenUpdate: (token) {
        print('token updated $token');
       
      },

      onTap: (NotificationTapDetails details) {
        print(
            "Notification tapped with ${details.appState} & payload ${details.payload}");
        if (details.appState.name == "open") {
          Get.to(() => BottomPage());
        } else {
          setState(() {
            redirect = 'bottom';
          });
        }
        setState(() {
          payload = details.payload;
        });
      },
      androidConfig: AndroidNotificationsConfig(
        channelIdGetter: (msg) => 'Notifications',
        iconGetter: (msg) => "@drawable/notification_icon",
      ),
      child: GetMaterialApp(
        title: 'My App',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        initialRoute: redirect,
        getPages: AppPages.pages,
      ),
    );

AndroidManifest.xml

 <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">
           
            <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>
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="Notifications" />
        <receiver android:name="com.google.firebase.messaging.FirebaseMessagingReceiver" android:exported="true" android:enabled="true">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </receiver>
  • I have tested but same issue two times notification coming when the app state is open
  • From two notification in second on on tap is not working
  • When click on background notification it also not working

@rithik-dev
Copy link
Owner

For icon should I do the same like this bellow? iconGetter: (msg) => "@drawable/notification_icon"

No, this icon is the app icon. The param name for this is appIconGetter.

@rithik-dev
Copy link
Owner

 return FirebaseNotificationsHandler(
      onFcmTokenInitialize: (token) {
        print('token $token');
       
      },
      onFcmTokenUpdate: (token) {
        print('token updated $token');
       
      },

      onTap: (NotificationTapDetails details) {
        print(
            "Notification tapped with ${details.appState} & payload ${details.payload}");
        if (details.appState.name == "open") {
          Get.to(() => BottomPage());
        } else {
          setState(() {
            redirect = 'bottom';
          });
        }
        setState(() {
          payload = details.payload;
        });
      },
      androidConfig: AndroidNotificationsConfig(
        channelIdGetter: (msg) => 'Notifications',
        iconGetter: (msg) => "@drawable/notification_icon",
      ),
      child: GetMaterialApp(
        title: 'My App',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        initialRoute: redirect,
        getPages: AppPages.pages,
      ),
    );

AndroidManifest.xml

 <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">
           
            <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>
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="Notifications" />
        <receiver android:name="com.google.firebase.messaging.FirebaseMessagingReceiver" android:exported="true" android:enabled="true">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </receiver>
  • I have tested but same issue two times notification coming when the app state is open
  • From two notification in second on on tap is not working
  • When click on background notification it also not working

You are not doing anything if the app state is not open... You're passing redirect in the material app.. but the MaterialApp will be created first, and then you'll receive a notification. And then, you're just setting a variable, and nothing else

@rashmiranjanrrs
Copy link
Author

Okay let try this but what will do for duplicate notification when the app is in foreground?

@rashmiranjanrrs
Copy link
Author

Please suggest something

@rithik-dev
Copy link
Owner

As I said, can you share the notification logs, so I can look into it? Because this was fixed in the major-refactor branch.

However, for quick fix, read this: #4 (comment)

@rashmiranjanrrs
Copy link
Author

I am in the major refactor branch but still duplicate issue and let me share you the logs

@rashmiranjanrrs
Copy link
Author

Here I am adding the logs please check
image

image

@rithik-dev
Copy link
Owner

I can see that the message ID is the same here, but not sure why this is happening. This duplicate notification is a known Firebase issue, but I handled it in this package using unique message IDs. Not sure what is happening in your case. Try to use the shouldHandleNotification param, where you can maintain a state variable containing the title and body and check whether to show the notification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants