0

How to show headsup notification and badge in xamarin form android, I am using firebase push notification.It shows heads up notification and badge count in some devices like Redmi 6 pro etc..., I have tried this link to implement push notification :-https://github.com/CrossGeeks/FirebasePushNotificationPlugin . And my json payload is like this.

{
"to":"push-token",
"priority": "high",
"notification": {
        "title": "Test",
        "body": "Mary sent you a message!",
        "sound": "default",
        "icon": "youriconname"
                }
 }

And it's working fine in iOS when app is in the killed state and app is in the background.And not getting when the app is open.

How to do this,Please help me...

John
  • 35
  • 7

1 Answers1

0

I guess the reason is you do not have a notification channel defined in your Activity.

In the MainActivity.cs You can call this method in the onCreate method :

void CreateNotificationChannel()
    {
        if (Build.VERSION.SdkInt < BuildVersionCodes.O)
        {
            // Notification channels are new in API 26 (and not a part of the
            // support library). There is no need to create a notification 
            // channel on older versions of Android.
            return;
        }

        var channel = new NotificationChannel(CHANNEL_ID, "FCM Notifications", NotificationImportance.Default)
                      {
                          Description = "**Description**"
                      };

        var notificationManager = (NotificationManager) GetSystemService(NotificationService);
        notificationManager.CreateNotificationChannel(channel);
    }

Where

    internal static readonly string CHANNEL_ID = "my_notification_channel";
    internal static readonly int NOTIFICATION_ID = 100; 

are the definition for channel id and notification id respectively.

In the MainActivity's OnCreate after loading XF call this :

LoadApplication(new App());
CreateNotificationChannel();

Good luck

Revert in case of queries

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • am added the above code.It doesn't show any headsup message when app is open.Also when the app is in the killed state not getting notifications.Its work fine when the app is in the background – John Apr 09 '19 at 12:11
  • You might wanna post a bug then, as this looks more like a plugin issue! – FreakyAli Apr 09 '19 at 12:18
  • Actually ,it's mistake from my side and now the headsup notification is working fine in vivo,but in redmi the floating notification is disabled for my channel and it's enabled in the default channel, how to enable this i my channel ,am tried with this link:- https://stackoverflow.com/questions/33172390/how-to-handle-system-alert-window-permission-not-being-auto-granted-on-some-pre ,but it doesn't work – John Apr 11 '19 at 11:48