When the notification is recieved following code is handling the message:
private void SendNotification(string message)
{
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
var notificationBuilder = new Notification.Builder(this)
.SetContentTitle("GCM Message")
.SetContentText(message)
.SetAutoCancel(true)
.SetContentIntent(pendingIntent);
var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
notificationManager.Notify(0, notificationBuilder.Build());
}
But nothing shows.
I'm debugging it it that would make any difference?
When I go to settings on the app on the device, "Show notifications" is checked.
Comment 1:
using (var notificationManager = NotificationManager.FromContext(ApplicationContext))
{
var title = "Title";
var channelName = "TestChannel"
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
NotificationChannel channel = null;
if (channel == null)
{
channel = new NotificationChannel(channelName, channelName, NotificationImportance.Low)
{
LockscreenVisibility = NotificationVisibility.Public
};
channel.SetShowBadge(true);
notificationManager.CreateNotificationChannel(channel);
}
channel.Dispose();
}
var bitMap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.notification_template_icon_bg);
var notificationBuilder = new NotificationCompat.Builder(ApplicationContext)
.SetContentTitle(title)
.SetContentText(message)
.SetLargeIcon(bitMap)
.SetShowWhen(false)
.SetChannelId(channelName);
var notification = notificationBuilder.Build();
notificationManager.Notify(0, notification);
}
Runnig that code, no errors but nothing shows up.
Thanks for the help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…