CrossGeeks / AzurePushNotificationPlugin

Azure Push Notification Plugin for Xamarin iOS and Android
MIT License
67 stars 34 forks source link

Android notification heads-up issue #41

Closed yoongmy closed 4 years ago

yoongmy commented 4 years ago

I implementing the push notification for android with firebase and testing in android 9 mobile. Everything works fine except the heads-up not showing as I already set for priority high in the payload.

Payload example in Azure notification hubs:- {"data":{"title":"Test", "body":"abc 123", "priority":"high"}}


Android 8 and above use channel to set important high for the heads-up. Possible to override the channel important level in onReceive event?

johnn82 commented 4 years ago

Not a real issue. Thing is a defaul channel is created in the Init(...) method with channel importance set to Default. To enable heads up notification you need to create a channel by yourself and set the channel importance to High manually.

To do the override call the the Init(createDefaultNotificationChannel: false), and then in your Application.OnCreate() method do:

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                NotificationManager notificationManager = (NotificationManager)GetSystemService(Android.Content.Context.NotificationService);

                notificationManager.CreateNotificationChannel(new NotificationChannel(
                    AzurePushNotificationManager.DefaultNotificationChannelId,
                    AzurePushNotificationManager.DefaultNotificationChannelName, 
                    NotificationImportance.High));
            }