Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Firebase Push notifications not showing on Android 8.0+ when app is closed

$
0
0

Hello, good day.

I'm having a problem with push notifications on firebase.
On Android 7.0 or lower, it works perfectly.
On Android 8.0+, when the app is on Foreground, the notifications show normally. But, when it is on background or closed, the notifications don't show at all.
I create the notification channel, if not the notifications wouldn't show on foreground. Is there something else I am missing, like a foreground service? I am not really an expert on Android.

Here is my code for the MyFirebaseMessagingService:

[Service(Name = "com.company.firebase.MyFirebaseMessagingService", Exported=true)]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    [BroadcastReceiver(Enabled = true)]
    [IntentFilter(new[] { Intent.ActionBootCompleted })]
    public class MyFirebaseMessagingService : FirebaseMessagingService
    {
        const string TAG = "MyFirebaseMsgService";
        public override void OnMessageReceived(RemoteMessage message)
        {
                body = message.GetNotification().Body;
                title = message.GetNotification().Title;
                SendNotification(body, title, message.Data);

        }

        void SendNotification(string messageBody, string title, IDictionary<string, string> data)
        {
            var intent = new Intent(this, typeof(MainActivity));
            intent.AddFlags(ActivityFlags.ClearTop);
            foreach (var key in data.Keys)
            {
                intent.PutExtra(key, data[key]);
            }

            var pendingIntent = PendingIntent.GetActivity(this,
                                                          MainActivity.NOTIFICATION_ID,
                                                          intent,
                                                          PendingIntentFlags.OneShot);

            var notificationBuilder = new Notification.Builder(Application.Context, MainActivity.CHANNEL_ID)
                                      .SetSmallIcon(Resource.Drawable.icon)
                                      .SetContentTitle(title)
                                      .SetContentText(messageBody)
                                      .SetAutoCancel(true)
                                      .SetContentIntent(pendingIntent)
                                      .SetChannelId(MainActivity.CHANNEL_ID);

            var notificationManager = NotificationManagerCompat.From(this);
            notificationManager.Notify(MainActivity.NOTIFICATION_ID, notificationBuilder.Build());
        }
    }

Also, looking at the Device logs, I get this when getting a Notification with the App closed:

No Channel found for pkg=com.company.app, channelId=null, id=0, tag=GCM-Notification:2144077335, opPkg=com.company.app, callingUid=10294, userId=0, incomingUserId=0, notificationUid=10294, notification=Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE)
See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
Use of stream types is deprecated for operations other than volume control
FirebaseMessaging   Unable to log event: analytics library is missing
FirebaseMessaging   java.lang.NumberFormatException: s == null
    at java.lang.Integer.parseInt(Integer.java:570)
    at java.lang.Integer.valueOf(Integer.java:794)
    at com.google.firebase.messaging.zzb.zzc(Unknown Source:60)
    at com.google.firebase.messaging.zzb.zzk(Unknown Source:2)
    at com.google.firebase.messaging.FirebaseMessagingService.zzn(Unknown Source:93)
    at com.google.firebase.messaging.FirebaseMessagingService.zzm(Unknown Source:66)
    at com.google.firebase.iid.zzb$2.run(Unknown Source:4)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)
FirebaseMessaging   Error while parsing timestamp in GCM event

The "No Channel found for pkg=..." message really catch my eye because I do create the channel. When I searched the error all I got was "You must create a notification channel", but I already do. Is it destroyed when the app is closed or suspended?

I am really lost here. Any help would be appreciated.
Thanks.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>