public override void OnReceive(Context context, Intent intent) { var title = "Zadanie do Wykonania!"; var message = intent.GetStringExtra("Content"); Intent backIntent = new Intent(context, typeof(MainView)); backIntent.SetFlags(ActivityFlags.NewTask); var resultIntent = new Intent(context, typeof(MainView)); PendingIntent pending = PendingIntent.GetActivities(context, 0, new Intent[] { backIntent, resultIntent }, PendingIntentFlags.OneShot); var builder = new Notification.Builder(context) .SetContentTitle(title) .SetContentText(message) .SetAutoCancel(true) .SetSmallIcon(Resource.Mipmap.Icon) .SetDefaults(NotificationDefaults.All); builder.SetContentIntent(pending); var notification = builder.Build(); var manager = NotificationManager.FromContext(context); manager.Notify(1331, notification); }
public override void OnReceive(Context context, Intent intent) { var title = "Hello world!"; var message = "Checkout this notification"; Intent backIntent = new Intent(context, typeof(Splash)); backIntent.SetFlags(ActivityFlags.NewTask); //The activity opened when we click the notification is SecondActivity //Feel free to change it to you own activity var resultIntent = new Intent(context, typeof(Splash)); PendingIntent pending = PendingIntent.GetActivities(context, 0, new Intent[] { backIntent, resultIntent }, PendingIntentFlags.OneShot); //var builder = // new Notification.Builder(context) // .SetContentTitle(title) // .SetContentText(message) // .SetAutoCancel(true) // .SetSmallIcon(Resource.Drawable.Icon) // .SetDefaults(NotificationDefaults.All); //builder.SetContentIntent(pending); //var notification = builder.Build(); //var manager = NotificationManager.FromContext(context); //manager.Notify(1331, notification); }
private void CreateNotification(string title, string desc) { var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; var uiIntent = new Intent(this, typeof(MainActivity)); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); var notification = builder.SetContentIntent(PendingIntent.GetActivities(this, 0, uiIntent, 0)) .SetSmallIcon(Android.Resource.Drawable.SymActionEmail) .SetTicker(title) .SetContentText(desc) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .SetAutoCancel(true).Build(); notificationManager.Notify(1, notification); }
private void sendNotification(String title, String messageBody) { Intent[] intents = new Intent[1]; Intent intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); intent.PutExtra("IncidentNo", title); intent.PutExtra("ShortDesc", messageBody); intent.PutExtra("Description", messageBody); intents[0] = intent; PendingIntent pendingIntent = PendingIntent.GetActivities(this, 0, intents, PendingIntentFlags.OneShot); Android.Net.Uri defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification); NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(this).SetSmallIcon(Resource.Drawable.icon).SetContentTitle(title) .SetContentText(messageBody).SetAutoCancel(true).SetSound(defaultSoundUri).SetContentIntent(pendingIntent) .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon)); NotificationManager notificationManager = (NotificationManager)this.GetSystemService(Context.NotificationService); notificationManager.Notify(0, notificationbuilder.Build()); }
async void StartTimer(int time) { instance = this; timer = time; // In minutes Intent mainActivity = new Intent(Application.Context, typeof(MainActivity)); Intent sleepIntent = new Intent(Application.Context, typeof(MainActivity)); sleepIntent.SetAction("Sleep"); PendingIntent defaultIntent = PendingIntent.GetActivities(Application.Context, 0, new Intent[] { mainActivity, sleepIntent }, PendingIntentFlags.UpdateCurrent); NotificationCompat.Builder notification = new NotificationCompat.Builder(Application.Context, "Opus.Channel") .SetVisibility(NotificationCompat.VisibilityPublic) .SetSmallIcon(Resource.Drawable.NotificationIcon) .SetContentTitle(GetString(Resource.String.sleep_timer)) .SetContentText(timer + " " + GetString(Resource.String.minutes)) .SetContentIntent(defaultIntent) .SetOngoing(true); NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService); while (timer > 0) { notification.SetContentText(timer + " " + (timer > 1 ? GetString(Resource.String.minutes) : GetString(Resource.String.minute))); notificationManager.Notify(1001, notification.Build()); await Task.Delay(60000); //One minute in ms timer -= 1; } Intent musicIntent = new Intent(Application.Context, typeof(MusicPlayer)); musicIntent.SetAction("SleepPause"); Application.Context.StartService(musicIntent); notificationManager.Cancel(1001); instance = null; StopSelf(); }
void PostNotification(string message) { Intent notifyIntent = new Intent(this, GetType()); notifyIntent.SetFlags(ActivityFlags.SingleTop); PendingIntent pendingIntent = PendingIntent.GetActivities(this, 0, new[] { notifyIntent }, PendingIntentFlags.UpdateCurrent); Notification notification = new Notification.Builder(this) .SetSmallIcon(Resource.Drawable.beacon_gray) .SetContentTitle("Estimote") .SetContentText(message) .SetAutoCancel(true) .SetContentIntent(pendingIntent) .Build(); notification.Defaults |= NotificationDefaults.Lights; notification.Defaults |= NotificationDefaults.Sound; _notificationManager.Notify(NOTIFICATION_ID, notification); TextView statusTextView = FindViewById <TextView>(Resource.Id.status); statusTextView.Text = message; }