private void NotifyNetworkMessengerConnected() { var intent = new Intent(this, typeof(MainActivity)).SetAction(Intent.ActionMain).AddCategory(Intent.CategoryLauncher); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0); Notification notification = new Notification.Builder(this) .SetContentTitle(this.GetString(Resource.String.service_notification_title)) .SetContentText(this.GetString(Resource.String.service_notification_text)) .SetTicker(this.GetString(Resource.String.service_notification_text)) .SetSmallIcon(Resource.Drawable.Play) .SetLargeIcon(BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.Play)) .SetContentIntent(pendingIntent) .SetOngoing(true) .Notification; this.StartForeground(6947, notification); }
/// <summary> /// This method builds a local notifaction and lauches it to the user with NotificationManager. /// </summary> /// <param name="message">The message in the Notification</param> 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) .SetSmallIcon(Resource.Drawable.icon) .SetContentTitle("Kompetansetorget") // can probably be extracted from the Bundle the same way as message. .SetContentText(message) .SetAutoCancel(true) .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate | NotificationDefaults.Lights) //.SetLights(16737792, 300, 100) .SetContentIntent(pendingIntent); var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Notify(0, notificationBuilder.Build()); }