protected override void OnMessage(Context context, Intent intent) { string message = string.Empty; var keys = intent.Extras.KeySet(); string notificationParamName = "message"; // Extract the push notification message from the intent. if (intent.Extras.ContainsKey(notificationParamName)) { message = intent.Extras.Get(notificationParamName).ToString(); var title = "New item added:"; string entityDataKEy = "entitydata"; if (intent.Extras.ContainsKey(entityDataKEy)) { string entityJson = intent.Extras.Get(entityDataKEy).ToString(); Offer entity = Newtonsoft.Json.JsonConvert.DeserializeObject <Offer>(entityJson); CustomerOfferListAdapter.Items.Add(entity); } // Create a notification manager to send the notification. var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; // Create a new intent to show the notification in the UI. PendingIntent contentIntent = PendingIntent.GetActivity(context, 0, new Intent(this, typeof(CustomerOffersActivity)), 0); // Create the notification using the builder. var builder = new Notification.Builder(context); //builder.SetAutoCancel(true); builder.SetContentTitle(title); builder.SetContentText(message); builder.SetSmallIcon(Resource.Drawable.Icon); builder.SetContentIntent(contentIntent); builder.SetShowWhen(true); var notification = builder.Build(); // Display the notification in the Notifications Area. notificationManager.Notify(1, notification); } }
public static async void ShowLocalNot(LocalNot not, Context context = null) { var cc = context ?? Application.Context; var builder = new Notification.Builder(cc); builder.SetContentTitle(not.title); bool containsMultiLine = not.body.Contains("\n"); if (Build.VERSION.SdkInt < BuildVersionCodes.O || !containsMultiLine) { builder.SetContentText(not.body); } builder.SetSmallIcon(not.smallIcon); builder.SetAutoCancel(not.autoCancel); builder.SetOngoing(not.onGoing); if (not.progress != -1) { builder.SetProgress(100, not.progress, false); } builder.SetVisibility(NotificationVisibility.Public); builder.SetOnlyAlertOnce(true); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var channelId = $"{cc.PackageName}.general"; var channel = new NotificationChannel(channelId, "General", (NotificationImportance)not.notificationImportance); NotManager.CreateNotificationChannel(channel); builder.SetChannelId(channelId); if (not.bigIcon != null) { if (not.bigIcon != "") { var bitmap = await GetImageBitmapFromUrl(not.bigIcon); if (bitmap != null) { builder.SetLargeIcon(bitmap); if (not.mediaStyle) { builder.SetStyle(new Notification.MediaStyle()); // NICER IMAGE } } } } if (containsMultiLine) { var b = new Notification.BigTextStyle(); b.BigText(not.body); builder.SetStyle(b); } if (not.actions.Count > 0) { List <Notification.Action> actions = new List <Notification.Action>(); for (int i = 0; i < not.actions.Count; i++) { var _resultIntent = new Intent(context, typeof(MainIntentService)); _resultIntent.PutExtra("data", not.actions[i].action); var pending = PendingIntent.GetService(context, 3337 + i + not.id, _resultIntent, PendingIntentFlags.UpdateCurrent ); actions.Add(new Notification.Action(not.actions[i].sprite, not.actions[i].name, pending)); } builder.SetActions(actions.ToArray()); } } builder.SetShowWhen(not.showWhen); if (not.when != null) { builder.SetWhen(CurrentTimeMillis((DateTime)not.when)); } var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(cc); var resultIntent = GetLauncherActivity(cc); if (not.data != "") { resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var _data = Android.Net.Uri.Parse(not.data); //"cloudstreamforms:tt0371746Name=Iron man=EndAll"); resultIntent.SetData(_data); stackBuilder.AddNextIntent(resultIntent); var resultPendingIntent = stackBuilder.GetPendingIntent(not.id, (int)PendingIntentFlags.UpdateCurrent); builder.SetContentIntent(resultPendingIntent); } else { stackBuilder.AddNextIntent(resultIntent); builder.SetContentIntent(GetCurrentPending()); } try { NotManager.Notify(not.id, builder.Build()); } catch { } }