locked
Firebase Push Notification Not Received on Android Device in Xamarin Android RRS feed

  • Question

  • User382967 posted

    Actually I tried to send notification for single device through Test On Device option in Console. It shows completed but notification not received by device. And then I tried postman and pushtry.com, both of them gave result "Firebase Push Notification Sent Successfully", although the android device(Google Pixel Version 9) not received. Please help me to resolve this problem.

    Thursday, February 28, 2019 11:42 AM

Answers

  • User166490 posted

    Hi @Mohanasundharam Try this code in your Receiver

     public const string PRIMARY_CHANNEL = "default";
        public void SendNotifications(RemoteMessage message)
        {
            NotificationManager manager = (NotificationManager)GetSystemService(NotificationService);
            var push = new Intent();
            var fullScreenPendingIntent = PendingIntent.GetActivity(this, 0,
                    push, PendingIntentFlags.CancelCurrent);
            NotificationCompat.Builder notification;
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var chan1 = new NotificationChannel(PRIMARY_CHANNEL,
                   new Java.Lang.String("Primary"), NotificationImportance.High);
                chan1.LightColor = Color.Green;
                manager.CreateNotificationChannel(chan1);
                notification = new NotificationCompat.Builder(this, PRIMARY_CHANNEL);
            }
            else
            {
                notification = new NotificationCompat.Builder(this);
            }
            notification.SetContentIntent(fullScreenPendingIntent)
                     .SetContentTitle(message.GetNotification().Title)
                     .SetContentText(message.GetNotification().Body)
                     .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon))
                     .SetSmallIcon(Resource.Drawable.icon_transparent)
                     .SetStyle((new NotificationCompat.BigTextStyle()))
                     .SetPriority(NotificationCompat.PriorityHigh)
                     .SetColor(0x9c6114)
                     .SetAutoCancel(true);
            manager.Notify(1, notification.Build());
        }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 5, 2019 7:38 AM

All replies

  • User371688 posted

    You can check the log information when you send the notification to see if there has the information about the notification just like following image:

    If you can can't see these information about the notification , this means that you haven't receive the notice.

    Friday, March 1, 2019 7:01 AM
  • User166490 posted

    Hi @Mohanasundharam , After Android 8.0 Version, Must We need to created Notification Channels,Then only will get the Notifications.More Please read this blog .. https://developer.android.com/training/notify-user/channels

    Tuesday, March 5, 2019 7:32 AM
  • User166490 posted

    Hi @Mohanasundharam Try this code in your Receiver

     public const string PRIMARY_CHANNEL = "default";
        public void SendNotifications(RemoteMessage message)
        {
            NotificationManager manager = (NotificationManager)GetSystemService(NotificationService);
            var push = new Intent();
            var fullScreenPendingIntent = PendingIntent.GetActivity(this, 0,
                    push, PendingIntentFlags.CancelCurrent);
            NotificationCompat.Builder notification;
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var chan1 = new NotificationChannel(PRIMARY_CHANNEL,
                   new Java.Lang.String("Primary"), NotificationImportance.High);
                chan1.LightColor = Color.Green;
                manager.CreateNotificationChannel(chan1);
                notification = new NotificationCompat.Builder(this, PRIMARY_CHANNEL);
            }
            else
            {
                notification = new NotificationCompat.Builder(this);
            }
            notification.SetContentIntent(fullScreenPendingIntent)
                     .SetContentTitle(message.GetNotification().Title)
                     .SetContentText(message.GetNotification().Body)
                     .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon))
                     .SetSmallIcon(Resource.Drawable.icon_transparent)
                     .SetStyle((new NotificationCompat.BigTextStyle()))
                     .SetPriority(NotificationCompat.PriorityHigh)
                     .SetColor(0x9c6114)
                     .SetAutoCancel(true);
            manager.Notify(1, notification.Build());
        }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 5, 2019 7:38 AM