public void PushNotification(string title, string message) { Intent notificationIntent = new Intent(Intent.ActionView); //notificationIntent.SetData(Android.Net.Uri.Parse(urlData)); PendingIntent pending = PendingIntent.GetActivity(context, 0, notificationIntent, PendingIntentFlags.CancelCurrent | PendingIntentFlags.Immutable); NotificationManager manager = NotificationManager.FromContext(context); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "My Notifications", NotificationImportance.Max); // Configure the notification channel. notificationChannel.Description = "Channel description"; notificationChannel.EnableLights(true); notificationChannel.LightColor = Color.AliceBlue; notificationChannel.SetVibrationPattern(new long[] { 0, 1000, 500, 1000 }); notificationChannel.EnableVibration(true); manager.CreateNotificationChannel(notificationChannel); } Notification.Builder builder = new Notification.Builder(context, CHANNEL_ID) .SetContentTitle(title) .SetContentText(message) .SetSmallIcon(Resource.Drawable.icon); builder.SetContentIntent(pending); Notification notification = builder.Build(); manager.Notify(1337, notification); }
/// <summary> /// Update the notification. /// </summary> /// <param name="context"> /// The context. /// </param> /// <returns> /// The updated notification. /// </returns> public Notification UpdateNotification(Context context) { if (builder == null) { builder = new Notification.Builder(context); } builder.SetContentTitle(this.Title); if (this.TotalBytes > 0 && this.CurrentBytes != -1) { builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false); } else { builder.SetProgress(0, 0, true); } builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes)); builder.SetContentInfo(context.GetString(Resource.String.time_remaining_notification, Helpers.GetTimeRemaining(this.TimeRemaining))); builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload); builder.SetOngoing(true); builder.SetTicker(this.Ticker); builder.SetContentIntent(this.PendingIntent); return(builder.Notification); }
public void ShowNotification(string title, string content) { CreatNotificationChannel(); Context context = Android.App.Application.Context; var intent = getLaucherActivity(); var stackBuiler = TaskStackBuilder.Create(context); stackBuiler.AddNextIntent(intent); var pendingIntent = stackBuiler.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); if (builder == null) { builder = new Notification.Builder(context, "channel_ID"); } builder.SetAutoCancel(true); builder.SetContentTitle(title); builder.SetContentIntent(pendingIntent); builder.SetContentText(content); // builder.SetSmallIcon(Resource.Drawable.ic_vol_type_tv_dark); // Resource.Drawable.ic_stat_button_click; Notification notification = builder.Build(); NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager; notificationManager.Notify(NOTIFICATION_ID, notification); }
private void HandleEnterZone(Zone z) { Log.Debug(TAG, "Enter zone " + z.Name); Intent notificationIntent = new Intent(this, typeof(NotificationActivity)); notificationIntent.PutExtra("zone_id", z.Id); notificationIntent.PutExtra("zone_name", z.Name); notificationIntent.PutExtra("zone_color", z.Color); notificationIntent.PutExtra("zone_alias", z.Alias); PendingIntent pendingIntent = PendingIntent.GetActivity( this, z.Id, notificationIntent, PendingIntentFlags.UpdateCurrent); Notification.Builder notificationBuilder = new Notification.Builder(this); notificationBuilder.SetSmallIcon(Resource.Drawable.elm_logo); notificationBuilder.SetContentTitle("New zone"); notificationBuilder.SetContentText("You have entered zone '" + z.Name + "'"); notificationBuilder.SetDefaults(NotificationDefaults.Sound); notificationBuilder.SetAutoCancel(true); notificationBuilder.SetContentIntent(pendingIntent); // Get an instance of the NotificationManager service NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); //Build the notification and issues it with notification manager. notificationManager.Notify(z.Id, notificationBuilder.Build()); }
//Classe que gerencia o envio das notificações public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var resultIntent = new Intent(context, typeof(AlarmReceiver)); var pending = PendingIntent.GetActivity(context, 0, resultIntent, PendingIntentFlags.CancelCurrent); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var builder = new Notification.Builder(context) .SetDefaults(NotificationDefaults.Sound) .SetContentIntent(pending) .SetContentTitle(title) .SetSmallIcon(Resource.Drawable.notify_panel_notification_icon_bg) .SetContentText(message) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true); builder.SetContentIntent(pending); var notification = builder.Build(); var manager = NotificationManager.FromContext(context); manager.Notify(0, notification); }
private void InitBlockChain() { if (BlockChainService.BlockChain == null) { BlockChainService.BlockChain = new BlockChainVotings(); BlockChainService.BlockChain.CheckRoot(); Task.Run(() => { BlockChainService.BlockChain.Start(); }); BlockChainService.BlockChain.NewVoting += (s, a) => { RunOnUiThread(() => { var notificationManager = GetSystemService(NotificationService) as NotificationManager; PendingIntent contentIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(MainActivity)), 0); var builder = new Notification.Builder(this); builder.SetAutoCancel(true); builder.SetContentTitle(Resources.GetString(Resource.String.newVoting)); builder.SetContentText(BlockChainService.BlockChain.GetVotingName(a.Data)); builder.SetSmallIcon(Resource.Drawable.Icon); builder.SetContentIntent(contentIntent); var notification = builder.Build(); notificationManager.Notify(1, notification); }); }; } }
public void Notify(string title, string message, string itemId) { var context = Application.Context; var resultIntent = new Intent(context, typeof(MainActivity)); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var pending = PendingIntent.GetActivity(context, 0, resultIntent, PendingIntentFlags.CancelCurrent); var pickedUpIntent = new Intent("PickedUp"); pickedUpIntent.PutExtra("itemId", itemId); var pendingPickedUpIntent = PendingIntent.GetBroadcast(context, 0, pickedUpIntent, PendingIntentFlags.CancelCurrent); var builder = new Notification.Builder(context) .SetContentTitle(title) .SetContentText(message) .SetSmallIcon(Resource.Drawable.icon) .SetDefaults(NotificationDefaults.All) .SetVisibility(NotificationVisibility.Public); builder.SetContentIntent(pending); var pickedUpAction = new Notification.Action(Resource.Drawable.abc_btn_check_material, "Picked Up", pendingPickedUpIntent); builder.AddAction(pickedUpAction); var notification = builder.Build(); notification.Flags = NotificationFlags.AutoCancel; var manager = NotificationManager.FromContext(context); manager.Notify(1337, notification); }
protected override void OnMessage(Context context, Intent intent) { string message = string.Empty; // Extract the push notification message from the intent. if (intent.Extras.ContainsKey("message")) { message = intent.Extras.Get("message").ToString(); var title = "Doctor Notification"; // Create a notification manager to send the notification. var notificationManager = GetSystemService(NotificationService) as NotificationManager; // Create a new intent to show the notification in the UI. PendingIntent contentIntent = PendingIntent.GetActivity(context, 0, new Intent(this, typeof(MainActivity)), 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.ic_launcher); builder.SetContentIntent(contentIntent); var notification = builder.Build(); // Display the notification in the Notifications Area. notificationManager.Notify(1, notification); ShowPopUp(context, message); } }
void CreateNotification() { NotificationManager manager = Android.App.Application.Context.GetSystemService(Context.NotificationService) as NotificationManager; var builder = new Notification.Builder(Android.App.Application.Context); builder.SetContentTitle("Test Notification"); builder.SetContentText("This is the body"); builder.SetAutoCancel(true); builder.SetSmallIcon(Resource.Drawable.clipboard); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var channelId = "com.companyname.briefing.general"; var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default); manager.CreateNotificationChannel(channel); builder.SetChannelId(channelId); } var resultIntent = Android.App.Application.Context.PackageManager.GetLaunchIntentForPackage(Android.App.Application.Context.PackageName); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Android.App.Application.Context); stackBuilder.AddNextIntent(resultIntent); var resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); builder.SetContentIntent(resultPendingIntent); manager.Notify(0, builder.Build()); }
private Notification CreateAndroidNotification(LocalNotification notification) { var builder = new Notification.Builder(Application.Context) .SetContentTitle(notification.Title) .SetContentText(notification.Text) .SetSmallIcon(Application.Context.ApplicationInfo.Icon) .SetAutoCancel(true); if (!string.IsNullOrEmpty(notification.Parameter)) { var intent = new Intent(Application.Context, (CrossLocalNotifications.Current as LocalNotifier).MainActivityType); intent.PutExtra("launch_param", notification.Parameter); builder.SetContentIntent(PendingIntent.GetActivity( Application.Context, 0, intent, 0)); } var nativeNotification = builder.Build(); nativeNotification.Defaults = NotificationDefaults.Sound | NotificationDefaults.Vibrate; return(nativeNotification); }
/// <summary> /// Update the notification. /// </summary> /// <param name="context"> /// The context. /// </param> /// <returns> /// The updated notification. /// </returns> public Notification UpdateNotification(Context context) { var builder = new Notification.Builder(context); if (!string.IsNullOrEmpty(this.PausedText)) { builder.SetContentTitle(this.PausedText); builder.SetContentText(string.Empty); builder.SetContentInfo(string.Empty); } else { builder.SetContentTitle(this.Title); if (this.TotalBytes > 0 && this.CurrentBytes != -1) { builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false); } else { builder.SetProgress(0, 0, true); } builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes)); builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining))); } builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload); builder.SetOngoing(true); builder.SetTicker(this.Ticker); builder.SetContentIntent(this.PendingIntent); return(builder.Notification); }
public override void OnMessageReceived(RemoteMessage message) { Notification.Builder builder = new Notification.Builder(this) .SetContentText(message.GetNotification().Body) .SetSmallIcon(Resource.Drawable.notification) .SetAutoCancel(true) .SetVisibility(NotificationVisibility.Public); var textStyle = new Notification.BigTextStyle(); textStyle.BigText(message.GetNotification().Body); builder.SetStyle(textStyle); Intent intent = new Intent(this, typeof(MainActivity)); const int pendingIntentId = 0; PendingIntent pendingIntent = PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot); // Launch SecondActivity when the users taps the notification: builder.SetContentIntent(pendingIntent); // Build the notification: Notification notification = builder.Build(); // Get the notification manager: NotificationManager notificationManager = GetSystemService(NotificationService) as NotificationManager; // Publish the notification: const int notificationId = 0; notificationManager.Notify(notificationId, notification); }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var resultintent = new Intent(context, typeof(MenuPdvs)); resultintent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var pending = PendingIntent.GetActivity(context, (int)TipoNotificacao.AlarmeAlmoco, resultintent, PendingIntentFlags.CancelCurrent); var builder = new Notification.Builder(context) .SetContentTitle(title) .SetContentText(message) .SetSmallIcon(Resource.Drawable.logosmartpromoter) .SetDefaults(NotificationDefaults.All); builder.SetContentIntent(pending); var notification = builder.Build(); var manager = NotificationManager.FromContext(context); manager.Notify((int)TipoNotificacao.AlarmeAlmoco, notification); }
public override void OnReceive(Context context, Intent intent) { using (var builder = new Notification.Builder(Application.Context)) { builder.SetContentTitle(TranslationCodeExtension.GetTranslation("HalfWorkTitle")) .SetContentText(TranslationCodeExtension.GetTranslation("HalfWorkText")) .SetAutoCancel(true) .SetSmallIcon(Resource.Drawable.icon); var manager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var channelId = $"{Application.Context.PackageName}.general"; var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default); manager.CreateNotificationChannel(channel); builder.SetChannelId(channelId); } var resultIntent = GetLauncherActivity(); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context); stackBuilder.AddNextIntent(resultIntent); var resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); builder.SetContentIntent(resultPendingIntent); manager.Notify(2, builder.Build()); CrossVibrate.Current.Vibration(TimeSpan.FromMilliseconds(150)); stackBuilder.Dispose(); } }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var number = intent.GetStringExtra("number"); try { SmsManager.Default.SendTextMessage(number, null, message, null, null); } catch (Java.Lang.IllegalArgumentException) { var resultIntent = new Intent(context, typeof(MainActivity)); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var pending = PendingIntent.GetActivity(context, 0, resultIntent, PendingIntentFlags.CancelCurrent); var builder = new Notification.Builder(context) .SetContentTitle("Ошибка") .SetContentText($"Сообщение на номер {number} не было отправлено") .SetSmallIcon(Resource.Drawable.alarm) .SetDefaults(NotificationDefaults.All); builder.SetContentIntent(pending); var notification = builder.Build(); var manager = NotificationManager.FromContext(context); manager.Notify(0, notification); } }
protected override void OnMessage(Context context, Intent intent) { var currentActivity = Mvx.Resolve <IMvxAndroidCurrentTopActivity>().Activity; var message = string.Empty; // Extract the push notification message from the intent. if (intent.Extras.ContainsKey("message")) { message = intent.Extras.Get("message").ToString(); var title = "New item added:"; // Create a notification manager to send the notification. var notificationManager = GetSystemService(NotificationService) as NotificationManager; // Create a new intent to show the notification in the UI. var contentIntent = PendingIntent.GetActivity(context, 0, new Intent(this, currentActivity.GetType()), 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.ic_launcher); builder.SetContentIntent(contentIntent); var notification = builder.Build(); // Display the notification in the Notifications Area. notificationManager.Notify(1, notification); } }
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 = intent.GetStringExtra(Constants.NotificationTitleKey); var body = intent.GetStringExtra(Constants.NotificationBodyKey); var id = intent.GetIntExtra(Constants.NotificationIdKey, 0); //Generating notification var builder = new Notification.Builder(Application.Context, Constants.NotificationChannelId) .SetContentTitle(title) .SetContentText(body) .SetSmallIcon(Resource.Drawable.ic_thebasics_not); var resultIntent = AndroidNotificationManager.GetLauncherActivity(); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context); stackBuilder.AddNextIntent(resultIntent); var resultPendingIntent = stackBuilder.GetPendingIntent(id, (int)PendingIntentFlags.Immutable); builder.SetContentIntent(resultPendingIntent); // Sending notification var notificationManager = NotificationManagerCompat.From(Application.Context); var notificationId = int.Parse(string.Format("{0}{1:00}{2:00}{3}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, id)); notificationManager.Notify(notificationId, builder.Build()); }
/// <summary> /// 產生本地端的推播通知 /// </summary> /// <param name="notificationPayload"></param> void createNotification(NotificationPayload notificationPayload) { #region 產生本地端的推播通知 #region 產生一個 Intent ,並且將要傳遞過去的推播參數,使用 PutExtra 放進去 var uiIntent = new Intent(this, typeof(MainActivity)); // 設定當使用點選這個通知之後,要傳遞過去的資料 var fooPayload = JsonConvert.SerializeObject(notificationPayload); uiIntent.PutExtra("NotificationPayload", fooPayload); #endregion //建立 Notification Builder 物件 Notification.Builder builder = new Notification.Builder(this); //設定本地端推播的內容 var notification = builder // 設定當點選這個本地端通知項目後,要顯示的 Activity .SetContentIntent(PendingIntent.GetActivity(this, 0, uiIntent, PendingIntentFlags.OneShot)) .SetSmallIcon(Android.Resource.Drawable.SymActionEmail) .SetTicker(notificationPayload.Title) .SetContentTitle(notificationPayload.Title) .SetContentText(notificationPayload.Message) //設定推播聲音 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) //當使用者點選這個推播通知,將會自動移除這個通知 .SetAutoCancel(true).Build(); //產生 notification 物件 var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; // 顯示本地通知: notificationManager.Notify(1, notification); #endregion }
public void ShowNotification(Intent intent) { var id = intent.GetIntExtra("id", 0); var title = intent.GetStringExtra("title"); var body = intent.GetStringExtra("message"); var main_intent = new Intent(this, typeof(MainActivity)); main_intent.PutExtra("type", "alarm"); main_intent.PutExtra("id", id); var builder = new Notification.Builder(this); //builder.SetGroup("keep.grass"); builder.SetTicker(title); builder.SetContentTitle(title); builder.SetContentText(body); builder.SetContentIntent ( PendingIntent.GetActivity ( this, id, main_intent, PendingIntentFlags.UpdateCurrent ) ); builder.SetSmallIcon(Resource.Drawable.icon); builder.SetLargeIcon(BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.icon)); builder.SetDefaults(NotificationDefaults.All); builder.SetAutoCancel(true); ((NotificationManager)this.GetSystemService(NotificationService)) .Notify(id, builder.Build()); }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var resultIntent = new Intent(context, typeof(SplashActivity)); var pending = PendingIntent.GetActivity(context, CueConstants.UniqueId, resultIntent, PendingIntentFlags.CancelCurrent); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var builder = new Notification.Builder(context, CueConstants.NotifId) .SetContentIntent(pending) .SetContentTitle(title) .SetSmallIcon(Resource.Drawable.coffee) .SetContentText(message) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetShowWhen(true) .SetAutoCancel(true); //TODO: SetWhen/SetShowWhen could be revisited for showing timestamps, but they currently aren't functional builder.SetContentIntent(pending); var notification = builder.Build(); var manager = NotificationManager.FromContext(context); manager.Notify(CueConstants.UniqueId, notification); }
static NotificationHandler() { Intent intent = new Intent(Application.Context, typeof(CurrentSong)); intent.AddFlags(ActivityFlags.SingleTop); PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent); builder = new Notification.Builder(Application.Context, CHANNEL_ID); builder.SetContentIntent(pendingIntent); builder.SetOngoing(true); if (Android.OS.Build.VERSION.SdkInt <= Android.OS.BuildVersionCodes.M) { CreateNotificationMediaActions(); } notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager; if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O) { /* Create or update. */ NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "tubeload song notification", NotificationImportance.Min); notificationManager.CreateNotificationChannel(channel); } }
//private NotificationManager notificationManager; #region ILocalNotifications implementation public void SendLocalNotification(string title, string description, long time) { var builder = new Notification.Builder(Application.Context) .SetContentTitle(title) .SetContentText(description) .SetWhen(time) .SetDefaults(NotificationDefaults.All) .SetSmallIcon(Resource.Drawable.icon); var notification = builder.Build(); var resultIntent = new Intent(Application.Context, typeof(AfazerService)); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var stackBuilder = TaskStackBuilder.Create(Application.Context); stackBuilder.AddNextIntent(resultIntent); var resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); builder.SetContentIntent(resultPendingIntent); var notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager; const int notificationId = 0; notificationManager?.Notify(notificationId, notification); }
//internal static bool void HandleNotification(string messageBody, string messageTitle) { var intent = new Intent(Forms.Context, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop); var pendingIntent = PendingIntent.GetActivity(Forms.Context, 0, intent, PendingIntentFlags.UpdateCurrent); var n = new Notification.Builder(Forms.Context); n.SetSmallIcon(Resource.Drawable.notification_template_icon_bg); n.SetLights(Android.Graphics.Color.Blue, 300, 1000); n.SetContentIntent(pendingIntent); n.SetContentTitle(messageTitle); n.SetTicker(messageBody); //n.SetLargeIcon(global::Android.Graphics.BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.icon)); n.SetAutoCancel(true); n.SetContentText(messageBody); n.SetVibrate(new long[] { 200, 200, 100, }); var nm = NotificationManager.FromContext(Forms.Context); nm.Notify(0, n.Build()); // Make call to Xamarin.Forms here with the event handler }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var resultIntent = new Intent(context, typeof(MainActivity)); resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask); var pending = PendingIntent.GetActivity(context, 0, resultIntent, PendingIntentFlags.CancelCurrent); var builder = new Notification.Builder(context) .SetContentTitle(title) .SetContentText(message) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetDefaults(NotificationDefaults.All) .SetAutoCancel(true); builder.SetContentIntent(pending); var notification = builder.Build(); var manager = NotificationManager.FromContext(context); manager.Notify(1337, notification); }
public override async void OnReceive(Context context, Intent intent) { try { if (!SimpleIoc.Default.IsRegistered <IApplicationService>()) { Log.Info("VERSION", "Application service not registered. Registering new instance..."); SimpleIoc.Default.Register <IApplicationService, ApplicationService>(); } NewVersion version = await VersionService.CheckForUpdates(); if (version != null) { string message = intent.GetStringExtra("message"); string title = intent.GetStringExtra("title"); Intent notificationIntent = new Intent(Intent.ActionView); notificationIntent.SetData(Android.Net.Uri.Parse(version.ReleaseUrl)); PendingIntent pending = PendingIntent.GetActivity(context, 0, notificationIntent, PendingIntentFlags.CancelCurrent | PendingIntentFlags.Immutable); NotificationManager manager = NotificationManager.FromContext(context); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "My Notifications", NotificationImportance.Max); // Configure the notification channel. notificationChannel.Description = "Channel description"; notificationChannel.EnableLights(true); notificationChannel.LightColor = Color.AliceBlue; notificationChannel.SetVibrationPattern(new long[] { 0, 1000, 500, 1000 }); notificationChannel.EnableVibration(true); manager.CreateNotificationChannel(notificationChannel); } Notification.Builder builder = new Notification.Builder(context, CHANNEL_ID) .SetContentTitle(title) .SetContentText(message) .SetSmallIcon(Resource.Drawable.icon); builder.SetContentIntent(pending); Notification notification = builder.Build(); manager.Notify(1337, notification); } } catch (Exception ex) { Log.Error("VERSION", ex.Message); } //PendingIntent pendingz = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent); //AlarmManager alarmManager = context.GetSystemService(Context.AlarmService).JavaCast<AlarmManager>(); //alarmManager.SetExact(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + 10 * 1000, pendingz); }
public void ShowNotification(string title, string messageTitle, string messege, bool handleClickNeeded ) { try { // Set up an intent so that tapping the notifications returns to this app: Intent intent = new Intent ( Application.Context , typeof( NotificationClick )); //intent.RemoveExtra ("MyData"); intent.PutExtra ("Message", messege); intent.PutExtra ("Title", title); string chatMsg = messege; string chatTouserID = ""; if( title == "chat" ) { string[] delimiters = { "&&" }; string[] clasIDArray = messege.Split(delimiters, StringSplitOptions.None); chatMsg = clasIDArray [0]; chatTouserID = clasIDArray [1]; } // Create a PendingIntent; we're only using one PendingIntent (ID = 0): const int pendingIntentId = 0; PendingIntent pendingIntent = PendingIntent.GetActivity ( MainActivity.GetMainActivity() , pendingIntentId, intent, PendingIntentFlags.OneShot); // Instantiate the builder and set notification elements: Notification.Builder builder = new Notification.Builder(MainActivity.GetMainActivity()) .SetContentTitle(title) .SetContentText(chatMsg) .SetDefaults(NotificationDefaults.Sound) .SetAutoCancel( true ) .SetSmallIcon(Resource.Drawable.app_icon); builder.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate); if( handleClickNeeded ) builder.SetContentIntent( pendingIntent ); // Build the notification: Notification notification = builder.Build(); // Get the notification manager: NotificationManager notificationManager = (NotificationManager)MainActivity.GetMainActivity().GetSystemService(Context.NotificationService); // Publish the notification: const int notificationId = 0; notificationManager.Notify(notificationId, notification); } catch (Exception ex) { string err = ex.Message; } }
public void WireAlarm(Intent intent) { //Show toast here //Toast.MakeText(context, "Hello it's me ", ToastLength.Short).Show(); var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); //Create intent for action 1 (TAKE) var actionIntent1 = new Intent(); actionIntent1.SetAction("TAKE"); var pIntent1 = PendingIntent.GetBroadcast(Android.App.Application.Context, 0, actionIntent1, PendingIntentFlags.CancelCurrent); //Create intent for action 2 (REPLY) var actionIntent2 = new Intent(); actionIntent2.SetAction("SKIP"); var pIntent2 = PendingIntent.GetBroadcast(Android.App.Application.Context, 0, actionIntent2, PendingIntentFlags.CancelCurrent); Intent resultIntent = Android.App.Application.Context.PackageManager.GetLaunchIntentForPackage(Android.App.Application.Context.PackageName); var contentIntent = PendingIntent.GetActivity(Android.App.Application.Context, 0, resultIntent, PendingIntentFlags.CancelCurrent); var pending = PendingIntent.GetActivity(Android.App.Application.Context, 0, resultIntent, PendingIntentFlags.CancelCurrent); //Debug.WriteLine(" Time -- : "+ m.ToString()); // Instantiate the Big Text style: Notification.BigTextStyle textStyle = new Notification.BigTextStyle(); var builder = new Notification.Builder(Android.App.Application.Context) .AddAction(Resource.Drawable.tick_notify, "TAKE", pIntent1) .AddAction(Resource.Drawable.cancel_notify, "SKIP", pIntent2) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetContentTitle("Diabetics Reminder") .SetDefaults(NotificationDefaults.Sound) .SetStyle(new Notification .BigTextStyle() .SetSummaryText("") .SetBigContentTitle(title) .BigText(message) ).SetDefaults(NotificationDefaults.All); builder.SetContentIntent(pending); var notification = builder.Build(); var manager = NotificationManager.FromContext(Android.App.Application.Context); manager.Notify(10010, notification); }
public void SentNoficationForNewInovoice(List <Customer> countNewНotifyNewInvoiceCustomers) { if (countNewНotifyNewInvoiceCustomers.Count > 0) { // Set up an intent so that tapping the notifications returns to this app: Intent intent = new Intent(this, typeof(MainActivity)); // Create a PendingIntent; const int pendingIntentId = 1; PendingIntent pendingIntent = PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot); // Instantiate the Inbox style: Notification.InboxStyle inboxStyle = new Notification.InboxStyle(); // Instantiate the builder and set notification elements: Notification.Builder bulideer = new Notification.Builder(this); bulideer.SetContentIntent(pendingIntent); bulideer.SetSmallIcon(Resource.Drawable.vik); // Set the title and text of the notification: bulideer.SetContentTitle("Нова фактура"); // bulideer.SetContentText("*****@*****.**"); foreach (var item in countNewНotifyNewInvoiceCustomers) { // Generate a message summary for the body of the notification: // if(item.DidGetNewInoviceToday == false) // { string money = item.MoneyToPay.ToString("C", System.Globalization.CultureInfo.GetCultureInfo("bg-BG")); inboxStyle.AddLine($"Аб. номер: {item.Nomer.ToString()}, {money}"); bulideer.SetContentText($"Аб. номер: {item.Nomer.ToString()}, {money}"); // item.DidGetNewInoviceToday = true; // } } // Plug this style into the builder: bulideer.SetStyle(inboxStyle); // Build the notification: Notification notification11 = bulideer.Build(); // Get the notification manager: NotificationManager notificationManager1 = GetSystemService(Context.NotificationService) as NotificationManager; // Publish the notification: const int notificationIdd = 1; notificationManager1.Notify(notificationIdd, notification11); } }
public static Notification.Builder SetLaunchActivity(this Notification.Builder builder, Type activityType) { var intent = new Intent(Application.Context, activityType); //intent.putExtra (...); // add some extras here var pendingIntent = PendingIntent.GetActivity(Application.Context, builder.GetHashCode(), intent, PendingIntentFlags.UpdateCurrent); builder.SetContentIntent(pendingIntent); return(builder); }
private static Notification GetNotification(Context ctx, int sessionId, NotificationOption not) { WorkshopDetail session = null; if (not.isWorkshop) { session = Services.Workshop.GetWorkshopFromBookingLocal(sessionId); } else { session = Services.Session.GetSession(sessionId); } var prefix = (not.isWorkshop) ? "" : "Session with "; Notification.Builder mBuilder = new Notification.Builder(ctx) .SetSmallIcon(Resource.Drawable.notificationIcon) .SetContentTitle(prefix + session.Title) .SetContentText(session.Time + " - " + session.DateHumanFriendly) .SetAutoCancel(true) .SetColor(ctx.Resources.GetColor(Resource.Color.primary)) .SetDefaults(NotificationDefaults.All) .SetStyle( new Notification.BigTextStyle().SetSummaryText(session.Title) .BigText(session.Time + " - " + session.DateHumanFriendly + System.Environment.NewLine + session.Room)); try { Looper.Prepare(); } catch (System.Exception ex) { } Intent resultIntent = new Intent(ctx, new ViewSessionActivity().Class); if (not.isWorkshop) { resultIntent = new Intent(ctx, new ViewWorkshopActivity().Class); } resultIntent.PutExtra("Id", sessionId); resultIntent.PutExtra("IsBooking", true); TaskStackBuilder stackBuilder = TaskStackBuilder.Create(ctx); stackBuilder.AddParentStack(new ViewWorkshopActivity().Class); stackBuilder.AddNextIntent(resultIntent); int identifier = (not.isWorkshop) ? 1 : 0; int notificationId = Integer.ParseInt(identifier + sessionId.ToString() + not.mins); PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(notificationId, PendingIntentFlags.UpdateCurrent); mBuilder.SetContentIntent(resultPendingIntent); return(mBuilder.Build()); }
void SendNotification(MessaggioNotifica m) { var intent = new Intent (this, typeof(MainActivity)); intent.AddFlags (ActivityFlags.ClearTop); var notifica = new Notification.Builder (this); switch (m.Tipo) { case "1": notifica.SetSmallIcon (Resource.Drawable.alert_1); break; case "2": notifica.SetSmallIcon (Resource.Drawable.alert_2); break; case "3": notifica.SetSmallIcon (Resource.Drawable.alert_3); break; default: notifica.SetSmallIcon (Resource.Drawable.InvioDoc); break; } if (m.Tipo == "4") { Messaggio mess = new Messaggio (m.Titolo, m.Messaggio); intent.PutExtra ("messaggio", JsonConvert.SerializeObject(mess)); } else { intent.PutExtra ("commessanum", m.Commessa); } var pendingIntent = PendingIntent.GetActivity (this, 0, intent, PendingIntentFlags.OneShot); notifica.SetContentTitle (m.Titolo); notifica.SetContentText (m.Messaggio); notifica.SetAutoCancel (true); notifica.SetContentInfo (m.Commessa); notifica.SetSubText ("Commessa " + m.Commessa); notifica.SetVibrate (new long[] {100,200,100}); notifica.SetSound (RingtoneManager.GetDefaultUri(RingtoneType.Notification)); notifica.SetContentIntent (pendingIntent); var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Notify (0, notifica.Build()); }
private static void ShowNativeNotification(Common.Message message, string notificationId, ButtonSet buttonSet = null, string alertTextOverride = null) { var nativeNotificationId = new Random().Next(); // Setup intent to launch application var context = Application.Context; // Build the notification var builder = new Notification.Builder(context) .SetContentTitle(message.SenderDisplayName) .SetSmallIcon(Resource.Drawable.donky_notification_small_icon_simple_push) .SetContentText(alertTextOverride ?? message.Body) .SetVibrate(new[] { 0L, 100L }) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)); var pushMessage = message as SimplePushMessage; if (pushMessage != null && buttonSet != null && buttonSet.ButtonSetActions.Any()) { builder.SetAutoCancel(false); // Jelly Bean + above supports multiple actions if (buttonSet.ButtonSetActions.Count == 2 && Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean) { foreach (var action in buttonSet.ButtonSetActions) { builder.AddAction(0, action.Label, CreateIntentForAction(context, nativeNotificationId, notificationId, action, pushMessage, buttonSet)); } } else { builder.SetContentIntent(CreateIntentForAction(context, nativeNotificationId, notificationId, buttonSet.ButtonSetActions[0], pushMessage, buttonSet)); } } else { var intent = CreateIntentForBasicPush(context, nativeNotificationId, notificationId); builder.SetContentIntent(intent) .SetAutoCancel(true); } // bug if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { builder.SetCategory(Notification.CategoryMessage) .SetPriority((int) NotificationPriority.High) .SetVisibility(NotificationVisibility.Public); // this is for a Heads-Up Notification (Out of App Notification) var push = new Intent(); push.AddFlags(ActivityFlags.NewTask); push.SetClass(context, Java.Lang.Class.FromType(context.GetType())); var fullScreenPendingIntent = PendingIntent.GetActivity(context, 0, push, PendingIntentFlags.CancelCurrent); builder .SetContentText(alertTextOverride ?? message.Body) .SetFullScreenIntent(fullScreenPendingIntent, true); } var notification = builder.Build(); notification.LedARGB = Color.White; notification.Flags |= NotificationFlags.ShowLights; notification.LedOnMS = 200; notification.LedOffMS = 2000; var notificationManager = (NotificationManager) context.GetSystemService(Context.NotificationService); notificationManager.Notify(nativeNotificationId, notification); }
//reads msgs from api every 3 sec private void getMsgs() { var thread = new Thread(async () => { MyMessage[] msgs; Notification.Builder builder = new Notification.Builder(this) .SetAutoCancel(true) .SetSmallIcon(Resource.Drawable.notif) .SetDefaults(NotificationDefaults.Sound); var nMgr = (NotificationManager)GetSystemService(NotificationService); Notification notification = new Notification(Resource.Drawable.notif, "message notification"); Intent intent = new Intent(this, typeof(ChatActivity)); PendingIntent pendingIntent; ViewModel myViewModel = ViewModel.myViewModelInstance; while (true) { string result = await ApiRequests.getMessages(MapActivity.client); msgs = JsonConvert.DeserializeObject<MyMessage[]>(result); if (notifCounter == 0) { for (int i = msgs.Length-1; i >=0; --i) { MyMessage msg = msgs[i]; if (!myViewModel.msgContainer.ContainsKey(msg.message_id)) { myViewModel.msgContainer.Add(msg.message_id, msg); myViewModel.msgsContainer.Add(msg); } } notifCounter++; } else { for (int i = msgs.Length-1; i >= 0; --i) { MyMessage msg = msgs[i]; if (!myViewModel.msgContainer.ContainsKey(msg.message_id)) { myViewModel.msgContainer.Add(msg.message_id, msg); myViewModel.msgsContainer.Add(msg); if (msg.msg_type.Equals("from")) { intent.PutExtra("email", msg.email); intent.PutExtra("firstName", msg.first_name); intent.PutExtra("lastName", msg.last_name); stackBuilder = Android.App.TaskStackBuilder.Create(this); stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MapActivity))); stackBuilder.AddNextIntent(intent); pendingIntent = PendingIntent.GetActivity(this, notifCounter++, intent, PendingIntentFlags.OneShot); builder.SetContentIntent(pendingIntent); builder.SetContentTitle(msg.first_name + " " + msg.last_name); builder.SetContentText(msg.message); nMgr.Notify(notifCounter++, builder.Build()); BroadcastStarted(msg); } } } } Thread.Sleep(3000); } }); thread.Start(); }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { base.OnStartCommand(intent, flags, startId); var notificationIntent = new Intent(BaseContext, typeof(MainActivity)); notificationIntent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop); var notifPendingIntent = PendingIntent.GetActivity(BaseContext, 0, notificationIntent, PendingIntentFlags.UpdateCurrent); var notif = new Notification { ContentIntent = notifPendingIntent }; Notification.Builder notifBuilder = new Notification.Builder(BaseContext); notifBuilder.SetContentIntent(notifPendingIntent); notifBuilder.SetWhen(JavaSystem.CurrentTimeMillis()); notifBuilder.SetSmallIcon(Resource.Drawable.Knock); notifBuilder.SetContentTitle(Resources.GetString(Resource.String.ApplicationName)); notifBuilder.SetContentText(Resources.GetString(Resource.String.NotifText)); StartForeground(Process.MyPid(), notifBuilder.Build()); //var notificationManager = (NotificationManager) BaseContext.GetSystemService(NotificationService); //notificationManager.Notify(Process.MyPid(), new Notification { ContentIntent = notifPendingIntent }); RegisterListener(); _wakeLockPartial?.Acquire(); Status = ServiceStatus.STARTED; Log.Debug("WakeUpService", "Service start command."); return StartCommandResult.StickyCompatibility; }
/// <summary> /// When we start on the foreground we will present a notification to the user /// When they press the notification it will take them to the main page so they can control the music /// </summary> void StartForeground () { var intent = new Intent (ApplicationContext, typeof (MainActivity)); intent.SetAction (Intent.ActionMain); intent.AddCategory (Intent.CategoryLauncher); ExtraUtils.PutSelectedTab (intent, (int) MainActivity.TabTitle.Player); var pendingIntent = PendingIntent.GetActivity ( ApplicationContext, 0, intent, PendingIntentFlags.UpdateCurrent ); var notificationBuilder = new Notification.Builder (ApplicationContext); notificationBuilder.SetContentTitle (CurrentEpisode.Title); notificationBuilder.SetContentText ( String.Format ( ApplicationContext.GetString (Resource.String.NotificationContentText), ApplicationContext.GetString (Resource.String.ApplicationName) ) ); notificationBuilder.SetSmallIcon (Resource.Drawable.ic_stat_av_play_over_video); notificationBuilder.SetTicker ( String.Format ( Application.GetString (Resource.String.NoticifationTicker), CurrentEpisode.Title ) ); notificationBuilder.SetOngoing (true); notificationBuilder.SetContentIntent (pendingIntent); StartForeground (NotificationId, notificationBuilder.Build()); }
/// <summary> /// Update the notification. /// </summary> /// <param name="context"> /// The context. /// </param> /// <returns> /// The updated notification. /// </returns> public Notification UpdateNotification(Context context) { var builder = new Notification.Builder(context); if (!string.IsNullOrEmpty(this.PausedText)) { builder.SetContentTitle(this.PausedText); builder.SetContentText(string.Empty); builder.SetContentInfo(string.Empty); } else { builder.SetContentTitle(this.Title); if (this.TotalBytes > 0 && this.CurrentBytes != -1) { builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false); } else { builder.SetProgress(0, 0, true); } builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes)); builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining))); } builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload); builder.SetOngoing(true); builder.SetTicker(this.Ticker); builder.SetContentIntent(this.PendingIntent); return builder.Notification; }
private static Notification GetNotification(Context ctx, int sessionId, NotificationOption not) { WorkshopDetail session = null; if (not.isWorkshop) session = Services.Workshop.GetWorkshopFromBookingLocal(sessionId); else session = Services.Session.GetSession(sessionId); var prefix = (not.isWorkshop) ? "" : "Session with "; Notification.Builder mBuilder = new Notification.Builder(ctx) .SetSmallIcon(Resource.Drawable.notificationIcon) .SetContentTitle(prefix + session.Title) .SetContentText(session.Time + " - " + session.DateHumanFriendly) .SetAutoCancel(true) .SetColor(ctx.Resources.GetColor(Resource.Color.primary)) .SetDefaults(NotificationDefaults.All) .SetStyle( new Notification.BigTextStyle().SetSummaryText(session.Title) .BigText(session.Time + " - " + session.DateHumanFriendly + System.Environment.NewLine + session.Room)); try { Looper.Prepare(); } catch (System.Exception ex) { } Intent resultIntent = new Intent(ctx, new ViewSessionActivity().Class); if (not.isWorkshop) resultIntent = new Intent(ctx, new ViewWorkshopActivity().Class); resultIntent.PutExtra("Id", sessionId); resultIntent.PutExtra("IsBooking", true); TaskStackBuilder stackBuilder = TaskStackBuilder.Create(ctx); stackBuilder.AddParentStack(new ViewWorkshopActivity().Class); stackBuilder.AddNextIntent(resultIntent); int identifier = (not.isWorkshop) ? 1 : 0; int notificationId = Integer.ParseInt(identifier + sessionId.ToString() + not.mins); PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(notificationId, PendingIntentFlags.UpdateCurrent); mBuilder.SetContentIntent(resultPendingIntent); return mBuilder.Build(); }
private void PopUpNotification(int id, string title, string message){ Notification.Builder mBuilder = new Notification.Builder (this) .SetSmallIcon (Resource.Drawable.ic_notification) .SetContentTitle (title) .SetContentText (message) .SetAutoCancel (true); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, typeof(MainActivity)); resultIntent.SetFlags(ActivityFlags.NewTask|ActivityFlags.ClearTask); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this); // Adds the back stack for the Intent (but not the Intent itself) //stackBuilder.AddParentStack(); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.AddNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent( 0, PendingIntentFlags.UpdateCurrent ); mBuilder.SetContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) GetSystemService(Context.NotificationService); // mId allows you to update the notification later on. mNotificationManager.Notify(id, mBuilder.Build()); }