public override void OnReceive(Context context, Intent intent) { if (!MainActivity.REPLY_ACTION.Equals(intent.Action)) return; var requestId = intent.GetIntExtra(MainActivity.REQUEST_CODE_KEY, -1); if (requestId == -1) return; var reply = GetMessageText(intent); using (var notificationManager = NotificationManagerCompat.From(context)) { // Create new notification to display, or re-build existing conversation to update with new response var notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder.SetSmallIcon(Resource.Drawable.reply); notificationBuilder.SetContentText(Application.Context.GetString(Resource.String.replied)); var repliedNotification = notificationBuilder.Build(); // Call notify to stop progress spinner. notificationManager.Notify(requestId, repliedNotification); } Toast.MakeText(context, $"Message sent: {reply}", ToastLength.Long).Show(); }
IEnumerator Load() { NotificationManager manager = NotificationManager.GetNotificationManager(); NotificationCompat.Builder builder = new NotificationCompat.Builder(); builder.SetContentTitle("必要なデータのダウンロード"); builder.SetContentText("ダウンロード中です"); builder.SetTicker("ダウンロード中です"); builder.SetSmallIcon(); builder.SetProgress(100, 0, true); manager.Notify(0, builder.Build()); www = new WWW("https://dl.dropboxusercontent.com/u/153254465/Unity%E7%B3%BB/test.unity3d"); while (!www.isDone && www.error == null) { builder.SetProgress(100, (int)(www.progress * 100), true); builder.SetNumber((int)(www.progress * 100)); manager.Notify(0, builder.Build()); yield return new WaitForEndOfFrame(); } builder.SetProgress(0, 0, false); Notification.Default defauls = Notification.Default.Sound | Notification.Default.Vibrate; builder.SetDefaults(defauls); builder.SetTicker("ダウンロードが完了しました"); builder.SetContentText("ダウンロードが完了しました"); builder.SetContentIntent(); manager.Notify(0, builder.Build()); }
public override void OnReceive (Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainScreen)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); int resourceId = Resource.Drawable.HappyBaby; var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.HappyBaby) .SetSound(Android.Net.Uri.Parse("android.resource://com.iinotification.app/"+ Resource.Raw.babySound)) .SetContentTitle("Hey Mom") .SetContentText("Here I'm :)") .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }
private void ButtonOnClick (object sender, EventArgs eventArgs) { // These are the values that we want to pass to the next activity Bundle valuesForActivity = new Bundle (); valuesForActivity.PutInt ("count", _count); // Create the PendingIntent with the back stack // When the user clicks the notification, SecondActivity will start up. Intent resultIntent = new Intent (this, typeof(SecondActivity)); resultIntent.PutExtras (valuesForActivity); // Pass some values to SecondActivity. TaskStackBuilder stackBuilder = TaskStackBuilder.Create (this); stackBuilder.AddParentStack (Class.FromType (typeof(SecondActivity))); stackBuilder.AddNextIntent (resultIntent); PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent (0, (int)PendingIntentFlags.UpdateCurrent); // Build the notification NotificationCompat.Builder builder = new NotificationCompat.Builder (this) .SetAutoCancel (true) // dismiss the notification from the notification area when the user clicks on it .SetContentIntent (resultPendingIntent) // start up this activity when the user clicks the intent. .SetContentTitle ("Button Clicked") // Set the title .SetNumber (_count) // Display the count in the Content Info .SetSmallIcon (Resource.Drawable.ic_stat_button_click) // This is the icon to display .SetContentText (String.Format ("The button has been clicked {0} times.", _count)); // the message to display. // Finally publish the notification NotificationManager notificationManager = (NotificationManager)GetSystemService (NotificationService); notificationManager.Notify (ButtonClickNotificationId, builder.Build ()); _count++; }
/// <summary> /// Show a local notification in the Notification Area and Drawer. /// </summary> /// <param name="title">Title of the notification</param> /// <param name="body">Body or description of the notification</param> /// <param name="id">Id of notifications</param> public void Show(string title, string body, int id = 0) { var builder = new NotificationCompat.Builder(Application.Context); builder.SetContentTitle(title); builder.SetContentText(body); builder.SetAutoCancel(true); if (NotificationIconId != 0) { builder.SetSmallIcon(NotificationIconId); } else { builder.SetSmallIcon(Resource.Drawable.plugin_lc_smallicon); } 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); var notificationManager = NotificationManagerCompat.From(Application.Context); notificationManager.Notify(id, builder.Build()); }
protected override void OnMessage (Context context, Intent intent) { //Push Notification arrived - print out the keys/values Intent received = new Intent (context, typeof(RecievedPush)); string pushMessage = intent.GetStringExtra ("message"); received.AddFlags (ActivityFlags.ReorderToFront); received.AddFlags (ActivityFlags.NewTask); received.PutExtra ("pushedMessage", pushMessage); if (intent == null || intent.Extras == null) { received.PutExtras (intent.Extras); foreach (var key in intent.Extras.KeySet()) { Console.WriteLine ("Key: {0}, Value: {1}"); } } PendingIntent notificationLaunch = PendingIntent.GetActivity (context, 1000, received, PendingIntentFlags.CancelCurrent ); NotificationManager manager = (NotificationManager)GetSystemService (Context.NotificationService); NotificationCompat.Builder builder = new NotificationCompat.Builder (context); builder.SetContentText (pushMessage); builder.SetContentIntent ( notificationLaunch); builder.SetContentTitle ("New Message"); builder.SetSmallIcon (Resource.Drawable.ic_action_chat); builder.SetStyle ( new NotificationCompat.InboxStyle()); builder.SetSound (RingtoneManager.GetDefaultUri (RingtoneType.Notification)); builder.SetVibrate (new long[] { 500, 300, 100, 1000, 300, 300, 300 ,300 }); manager.Notify (1000, builder.Build ()); Buddy.RecordNotificationReceived(intent); }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { var LocationServiceIntent = new Intent ("com.ETCTimeApp.SaveLocationService"); pendingSaveLocationServiceIntent = PendingIntent.GetService (this, 0, LocationServiceIntent, 0); alarm = (AlarmManager)this.BaseContext.GetSystemService (Context.AlarmService); //repeat every 10 minutes alarm.SetRepeating (AlarmType.RtcWakeup, 10000, 1 * 5000 * 60, pendingSaveLocationServiceIntent); var pendingIntent = PendingIntent.GetActivity (this, 1, new Intent (this, typeof(MainActivity)), 0); var resultString = "Location service is running on background!"; int ic_small = Resource.Drawable.gps_small; var builder = new NotificationCompat.Builder (this) .SetAutoCancel (true) .SetContentIntent (pendingIntent) .SetContentTitle ("ETC Location Notification") .SetSmallIcon (ic_small) .SetContentText (resultString); // start our service foregrounded, that way it won't get cleaned up from memory pressure StartForeground ((int)NotificationFlags.ForegroundService, builder.Build ()); return StartCommandResult.Sticky; }
private void CreateNotification(Intent intent) { recipe = Recipe.FromBundle(intent.GetBundleExtra(Constants.ExtraRecipe)); List<Notification> notificationPages = new List<Notification> (); int stepCount = recipe.RecipeSteps.Count; for (int i = 0; i < stepCount; i++) { Recipe.RecipeStep recipeStep = recipe.RecipeSteps [i]; var style = new NotificationCompat.BigTextStyle (); style.BigText (recipeStep.StepText); style.SetBigContentTitle (String.Format (Resources.GetString (Resource.String.step_count), i + 1, stepCount)); style.SetSummaryText (""); var builder = new NotificationCompat.Builder (this); builder.SetStyle (style); notificationPages.Add (builder.Build ()); } var notifBuilder = new NotificationCompat.Builder(this); if (recipe.RecipeImage != null) { Bitmap recipeImage = Bitmap.CreateScaledBitmap( AssetUtils.LoadBitmapAsset(this, recipe.RecipeImage), Constants.NotificationImageWidth, Constants.NotificationImageHeight, false); notifBuilder.SetLargeIcon(recipeImage); } notifBuilder.SetContentTitle (recipe.TitleText); notifBuilder.SetContentText (recipe.SummaryText); notifBuilder.SetSmallIcon (Resource.Mipmap.ic_notification_recipe); Notification notification = notifBuilder.Extend(new NotificationCompat.WearableExtender().AddPages(notificationPages)).Build(); notificationManager.Notify (Constants.NotificationId, notification); }
public void ShowLocalNotification () { // Pass value to the next form: // Bundle valuesForActivity = new Bundle(); // valuesForActivity.PutInt("count", count); // When the user clicks the notification, SecondActivity will start up. //Intent resultIntent = new Intent(this, typeof(SecondActivity)); // Pass some values to SecondActivity: //resultIntent.PutExtras(valuesForActivity); var ctx = Forms.Context; // Build the notification: NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentTitle("Title Notification") // Set the title .SetSmallIcon(Resource.Drawable.icon) // This is the icon to display .SetContentText(String.Format("Message Notification")); // the message to display. // Finally, publish the notification: NotificationManager notificationManager = (NotificationManager)ctx.GetSystemService(Context.NotificationService); notificationManager.Notify(notificationId, builder.Build()); }
public override void OnReceive(Context context, Intent intent) { var id = intent.GetStringExtra("id"); var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainActivity)); notIntent.PutExtra("id", id); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From(context); int resourceId = Resource.Drawable.ic_launcher_xx; var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)); //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.ic_launcher_xx) .SetContentTitle(title) .SetContentText(message) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(int.Parse(id), notification); }
protected override void OnHandleIntent (Intent intent) { Context context = ApplicationContext; // var alarm = (Alarm)intent.GetParcelableExtra (ALARM_KEY); // TODO - workaround https://github.com/googlesamples/android-DirectBoot/issues/4 Bundle bundle = intent.Extras; var alarm = new Alarm { Id = bundle.GetInt ("id"), Year = bundle.GetInt ("year"), Month = bundle.GetInt ("month"), Day = bundle.GetInt ("day"), Hour = bundle.GetInt ("hour"), Minute = bundle.GetInt ("minute") }; var manager = context.GetSystemService (NotificationService).JavaCast<NotificationManager> (); var builder = new NotificationCompat.Builder (context) .SetSmallIcon (Resource.Drawable.ic_fbe_notification) .SetCategory (Notification.CategoryAlarm) .SetSound (Settings.System.DefaultAlarmAlertUri) .SetContentTitle (context.GetString (Resource.String.alarm_went_off, alarm.Hour, alarm.Minute)); manager.Notify (alarm.Id, builder.Build ()); var alarmStorage = new AlarmStorage (context); alarmStorage.DeleteAlarm (alarm); var wentoffIntent = new Intent (ALARM_WENT_OFF_ACTION); wentoffIntent.PutExtra (ALARM_KEY, alarm); LocalBroadcastManager.GetInstance (context).SendBroadcast (wentoffIntent); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState) { var ignored = base.OnCreateView(inflater, container, savedInstanceState); var view = inflater.Inflate(Resource.Layout.fragment_profile, null); imageLoader = new ImageLoader(Activity); view.FindViewById<TextView>(Resource.Id.profile_name).Text = "James Montemagno"; view.FindViewById<TextView>(Resource.Id.profile_description).Text = "James Montemagno is a Developer Evangelist at Xamarin and Microsoft MVP. He has been a .NET developer for over a decade working in a wide range of industries and before joining Xamarin was a professional mobile developer on the Xamarin platform for over 4 years. He can be found on Twitter @JamesMontemagno and blogs regularly at www.MotzCod.es"; imageLoader.DisplayImage("https://pbs.twimg.com/profile_images/618564939523862528/TMHi-4M-.jpg", view.FindViewById<ImageView>(Resource.Id.profile_image), -1); view.FindViewById<ImageView>(Resource.Id.profile_image).Click += (sender, args) => { var builder = new NotificationCompat.Builder(Activity) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetContentTitle("Click to go to friend details!") .SetContentText("New Friend!!"); var friendActivity = new Intent(Activity, typeof(FriendActivity)); PendingIntent pendingIntent = PendingIntent.GetActivity(Activity, 0, friendActivity, 0); builder.SetContentIntent(pendingIntent); builder.SetAutoCancel(true); var notificationManager = (NotificationManager) Activity.GetSystemService(Context.NotificationService); notificationManager.Notify(0, builder.Build()); }; return view; }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState) { var ignored = base.OnCreateView(inflater, container, savedInstanceState); var view = inflater.Inflate(Resource.Layout.fragment_profile, null); m_ImageLoader = new ImageLoader(Activity); view.FindViewById<TextView>(Resource.Id.profile_name).Text = "James Montemagno"; view.FindViewById<TextView>(Resource.Id.profile_description).Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum."; m_ImageLoader.DisplayImage("https://lh6.googleusercontent.com/-cGOyhvv0Xb0/UQV41NcgFHI/AAAAAAAAKz4/MKYmmtSgajI/w140-h140-p/6b27f0ec682011e2bd9a22000a9f14ba_7.jpg", view.FindViewById<ImageView>(Resource.Id.profile_image), -1); view.FindViewById<ImageView>(Resource.Id.profile_image).Click += (sender, args) => { var builder = new NotificationCompat.Builder(Activity) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetContentTitle("Click to go to friend details!") .SetContentText("New Friend!!"); var friendActivity = new Intent(Activity, typeof(FriendActivity)); PendingIntent pendingIntent = PendingIntent.GetActivity(Activity, 0, friendActivity, 0); builder.SetContentIntent(pendingIntent); builder.SetAutoCancel(true); var notificationManager = (NotificationManager) Activity.GetSystemService(Context.NotificationService); notificationManager.Notify(0, builder.Build()); }; return view; }
public override void OnReceive (Context context, Intent intent) { if (RetreiveLatestReceiver.IsAvailableVersion(context)) { intent.PutExtra ("title", string.Format(context.Resources.GetString(Resource.String.notification_title), "WhatsApp " + RetreiveLatestReceiver.GetLatestVersion ())); intent.PutExtra ("message", string.Format(context.Resources.GetString(Resource.String.notification_description), context.Resources.GetString(Resource.String.app_name))); var message = intent.GetStringExtra ("message"); var title = intent.GetStringExtra ("title"); var notIntent = new Intent (context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity (context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From (context); var style = new NotificationCompat.BigTextStyle ().BigText (message); int resourceId = Resource.Drawable.ic_launcher; var wearableExtender = new NotificationCompat.WearableExtender ().SetBackground (BitmapFactory.DecodeResource (context.Resources, resourceId)); // Generate notification (short text and small icon) var builder = new NotificationCompat.Builder (context); builder.SetContentIntent (contentIntent); builder.SetSmallIcon (Resource.Drawable.ic_launcher); builder.SetContentTitle (title); builder.SetContentText (message); builder.SetStyle (style); builder.SetWhen (Java.Lang.JavaSystem.CurrentTimeMillis ()); // When the AlarmManager will check changes? builder.SetAutoCancel (true); builder.Extend (wearableExtender); // Support Android Wear, yeah! var notification = builder.Build (); manager.Notify (0, notification); } }
private void ShowNotification(string message) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context) .SetContentTitle("CallMinder detected call") .SetSmallIcon(Android.Resource.Drawable.SymActionCall) .SetContentText(message); NotificationManager notificationManager = (NotificationManager) this.context.GetSystemService(Context.NotificationService); notificationManager.Notify(101, builder.Build()); }
public void Show (string message) { var builder = new NotificationCompat.Builder (Forms.Context) .SetAutoCancel (true) .SetContentTitle ("Button Clicked") .SetSmallIcon (Resource.Drawable.icon) .SetContentText (message); var notificationManager = (NotificationManager)Forms.Context.GetSystemService (Context.NotificationService); notificationManager.Notify (NotificationId, builder.Build ()); }
public void CallWebService() { _timer = new System.Threading.Timer(async (o) => { var dadosAPI = await CallAPI_Droid.ExecChamadaAPIComRetornoString(EnumCallAPI.Promo); if (String.IsNullOrEmpty(dadosAPI)) return; // Configurando URL recebida pelo serviço var xmlString = this.XMLDeserialization(dadosAPI); App.URL = xmlString.Text.Split(',')[0]; // Salvando imagem e carregando o Bitmap var saveImage = new SaveAndLoadFile_Droid(); var imageName = String.Concat(System.IO.Path.GetRandomFileName().Split('.')[0], ".jpg"); Bitmap bmpImagem = null; if (saveImage.BaixaImagemSalvarEmDisco(imageName, xmlString.Text.Split(',')[1])) bmpImagem = BitmapFactory.DecodeFile(saveImage.GetImage(imageName)); // Construindo Intent para carregamento da Activity var intent = new Intent(this, typeof(MainActivity)); // Construindo PendingIntent const int pendingIntentID = 0; var pendingIntent = PendingIntent.GetActivity(this, pendingIntentID, intent, PendingIntentFlags.OneShot); // Construindo a notificação NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .SetContentIntent(pendingIntent) .SetAutoCancel(true) .SetContentTitle("Nova Promoção") .SetSmallIcon(Resource.Drawable.ic_stat_bu_bling) .SetContentText("Clique aqui para ter acesso a nova promoção"); if (bmpImagem != null && bmpImagem.ByteCount > 0) builder.SetLargeIcon(bmpImagem); if ((int)Android.OS.Build.VERSION.SdkInt >= 21) { builder.SetVisibility(0); builder.SetCategory(Android.App.Notification.CategoryPromo); } // Publicando a notificação NotificationManager notificationManager = (NotificationManager)GetSystemService("notification"); notificationManager.Notify(10, builder.Build()); }, null, 0, 1800000); }
void BuildLocalOnlyNotification(string title, string content, int notificationId, bool withDismissal) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.SetContentTitle (title) .SetContentText (content) .SetLocalOnly (true) .SetSmallIcon (Resource.Drawable.ic_launcher); if (withDismissal) { Intent dismissalIntent = new Intent (Constants.ActionDismiss); dismissalIntent.PutExtra (Constants.KeyNotificationId, Constants.BothId); PendingIntent pendingIndent = PendingIntent.GetService (this, 0, dismissalIntent, PendingIntentFlags.UpdateCurrent); builder.SetDeleteIntent(pendingIndent); } NotificationManagerCompat.From (this).Notify (notificationId, builder.Build ()); }
private void SendNotification (string titles, string texts, string minimizedContent) { PendingIntent contentIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(MainActivity)), PendingIntentFlags.UpdateCurrent); NotificationCompat.Builder notiBuild = new NotificationCompat.Builder (this) .SetAutoCancel (false) .SetContentTitle (titles) .SetContentText (minimizedContent) .SetSmallIcon(Resource.Mipmap.ic_launcher) .SetTicker ("API Update") .SetStyle(new NotificationCompat.BigTextStyle().BigText(texts)) .SetOngoing(true) .SetContentIntent(contentIntent); NotificationManager notiManager = (NotificationManager)GetSystemService (Context.NotificationService); notiManager.Notify (notiId, notiBuild.Build()); }
/** * Adds a new {@link Notification} with sample data and sends it to the system. * Then updates the current number of displayed notifications for this application and * creates a notification summary if more than one notification exists. */ void AddNotificationAndUpdateSummaries () { // Create a Notification and notify the system. var builder = new NotificationCompat.Builder (Activity) .SetSmallIcon (Resource.Mipmap.ic_notification) .SetContentTitle (GetString (Resource.String.app_name)) .SetContentText (GetString (Resource.String.sample_notification_content)) .SetAutoCancel (true) .SetDeleteIntent (deletePendingIntent) .SetGroup (NOTIFICATION_GROUP); Notification notification = builder.Build (); notificationManager.Notify (GetNewNotificationId (), notification); CommonSampleLibrary.Log.Info (TAG, "Add a notification"); UpdateNotificationSummary (); UpdateNumberOfNotifications (); }
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 defaultSoundUri = RingtoneManager.GetDefaultUri (RingtoneType.Notification); var notificationBuilder = new NotificationCompat.Builder (this) .SetSmallIcon (Resource.Drawable.ic_stat_ic_notification) .SetContentTitle ("GCM Message") .SetContentText (message) .SetAutoCancel (true) .SetSound (defaultSoundUri) .SetContentIntent (pendingIntent); var notificationManager = (NotificationManager)GetSystemService (Context.NotificationService); notificationManager.Notify (0, notificationBuilder.Build ()); }
public CustomNavigationNotification(Context applicationContext) { notificationManager = (NotificationManager)applicationContext.GetSystemService(Context.NotificationService); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { NotificationChannel notificationChannel = new NotificationChannel( CUSTOM_CHANNEL_ID, CUSTOM_CHANNEL_NAME, NotificationImportance.Low ); notificationManager.CreateNotificationChannel(notificationChannel); } customNotificationBuilder = new NotificationCompat.Builder(applicationContext, CUSTOM_CHANNEL_ID) .SetSmallIcon(Resource.Drawable.ic_navigation) .SetContentTitle("Custom Navigation Notification") .SetContentText("Display your own content here!") .SetContentIntent(CreatePendingStopIntent(applicationContext)); customNotification = customNotificationBuilder.Build(); }
public void SendNotificatios(string body, string Header) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0); var builder = new NotificationCompat.Builder(this, GetString(Resource.String.channel_name)) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentIntent(pendingIntent) // Start up this activity when the user clicks the intent. .SetContentTitle(Header) .SetNumber(count) .SetContentText(body) .SetSmallIcon(Resource.Mipmap.ic_launcher); // This is the icon to display NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService); notificationManager.Notify(1, builder.Build()); count++; }
private void SendNotification(string body) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification); var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.icon) .SetContentTitle("CM App") .SetContentText(body) .SetAutoCancel(true) .SetSound(defaultSoundUri) .SetContentIntent(pendingIntent); var notificationManager = NotificationManager.FromContext(this); notificationManager.Notify(0, notificationBuilder.Build()); }
public override void ProcessNotification(Context context, string notificationType, string json) { var manager = (NotificationManager)context.GetSystemService(Context.NotificationService); var intent = context.PackageManager.GetLaunchIntentForPackage(context.PackageName); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.UpdateCurrent); var builder = new NotificationCompat.Builder(context) .SetSmallIcon(Android.Resource.Drawable.StarBigOn) .SetContentTitle("Boop!") .SetStyle(new NotificationCompat.BigTextStyle().BigText(json)) .SetContentText(json) .SetContentIntent(pendingIntent); manager.Notify(1, builder.Build()); }
void SendNotification(string messageBody) { try { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification) .SetContentTitle("Title") .SetContentText(messageBody) .SetAutoCancel(true) .SetContentIntent(pendingIntent); NotificationManagerCompat notificationManager = NotificationManagerCompat.From(this); notificationManager.Notify(0, notificationBuilder.Build()); } catch (Exception ex) { } }
private void SendNotification(string messageBody, string title) { var intent = new Intent(this, typeof(FormsActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); var notificationBuilder = new NotificationCompat.Builder(this, FormsActivity.ChannelId); notificationBuilder.SetContentTitle(title) .SetSmallIcon(Resource.Drawable.pic_dragon) .SetContentText(messageBody) .SetAutoCancel(true) .SetShowWhen(false) .SetContentIntent(pendingIntent); var notificationManager = NotificationManager.FromContext(this); notificationManager.Notify(0, notificationBuilder.Build()); }
void SendNotification(string messageBody) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); var notificationBuilder = new NotificationCompat.Builder(this, MainActivity.CHANNEL_ID); notificationBuilder.SetContentTitle("FCM Message") .SetSmallIcon(Resource.Mipmap.ic_launcher) .SetContentText(messageBody) .SetAutoCancel(true) .SetShowWhen(false) .SetContentIntent(pendingIntent); var notificationManager = NotificationManager.FromContext(this); notificationManager.Notify(0, notificationBuilder.Build()); }
private void SendNotification(RemoteMessage.Notification message)//metodo de generacion de la notificacion de forma local { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification); var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.logoOtb) .SetContentTitle(message.Title) .SetContentText(message.Body) .SetAutoCancel(true) .SetSound(defaultSoundUri) .SetContentIntent(pendingIntent); var notificationManager = NotificationManager.FromContext(this); notificationManager.Notify(0, notificationBuilder.Build()); }
internal static void SendCloudClipboardNotification(Context context, string receivedText) { var intent = new Intent(context, typeof(CloudClipboardService)); intent.SetAction("CloudClipboardCopy"); var pendingIntent = PendingIntent.GetService(context, 0, intent, PendingIntentFlags.UpdateCurrent); var notificationBuilder = new NotificationCompat.Builder(context) .SetSmallIcon(Resource.Drawable.Icon) .SetPriority((int)NotificationPriority.Min) .SetContentTitle("Universal clipboard - Tap to copy") .SetContentText(receivedText) .SetContentIntent(pendingIntent); var notificationManager = NotificationManager.FromContext(context); notificationManager.Notify(1, notificationBuilder.Build()); }
void ParsePush_ParsePushNotificationReceived(object sender, ParsePushNotificationEventArgs e) { var intent = new Intent(Context, typeof(MainActivity)); PendingIntent pendingIntent = PendingIntent.GetActivity(Context, 0, intent, PendingIntentFlags.OneShot); NotificationCompat.Builder builder = new NotificationCompat.Builder(Context) .SetContentTitle("Doorduino") .SetAutoCancel(true) .SetContentText(e.Payload["alert"].ToString()) .SetPriority((int)NotificationPriority.High) .SetVisibility((int)NotificationVisibility.Public) .SetCategory(Notification.CategoryAlarm) .SetContentIntent(pendingIntent) .SetDefaults((int)(NotificationDefaults.Sound | NotificationDefaults.Vibrate)) .SetSmallIcon(Android.Resource.Drawable.IcMenuSend); var notification = builder.Build(); var notificationManager = (NotificationManager)Context.GetSystemService(Context.NotificationService); notificationManager.Notify(0, notification); }
public override void OnReceive(Context context, Intent intent) { var bigStyle = new NotificationCompat.BigTextStyle().BigText("Telah Terjadi Tsunami"); // Create a PendingIntent; we're only using one PendingIntent (ID = 0): NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager; NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MainActivity.CHANNEL_ID) // .SetContentIntent(pendingIntent) .SetContentTitle("Sirine Tsunami") .SetContentText("Sirine Tsunami") .SetAutoCancel(true) .SetStyle(bigStyle) .SetSound(soundUri) .SetPriority(NotificationCompat.PriorityMax) .SetSmallIcon(Resource.Drawable.icontsunami); if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { builder.SetVisibility(NotificationCompat.VisibilityPublic); } Intent intents = new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://inatews.bmkg.go.id/terkini.php")); PendingIntent pendingIntent = PendingIntent.GetActivity(context, MainActivity.NOTIFICATION_ID, intents, PendingIntentFlags.UpdateCurrent); Intent buttonIntent = new Intent(context, typeof(DissmisService)); buttonIntent.PutExtra("notificationId", MainActivity.CHANNEL_ID); PendingIntent dismissIntent = PendingIntent.GetBroadcast(context, MainActivity.NOTIFICATION_ID, buttonIntent, PendingIntentFlags.CancelCurrent); builder.AddAction(Resource.Drawable.abc_ic_menu_overflow_material, "VIEW", pendingIntent); builder.AddAction(Resource.Drawable.abc_ic_menu_cut_mtrl_alpha, "DISMISS", dismissIntent); NotifyBroadcastReceived.ringtone = NotifyBroadcastReceived.ringtone ?? RingtoneManager.GetRingtone(context, soundUri); if (!NotifyBroadcastReceived.ringtone.IsPlaying) { NotifyBroadcastReceived.ringtone.Play(); } notificationManager.Notify(MainActivity.NOTIFICATION_ID, builder.Build()); }
public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra("message"); var title = intent.GetStringExtra("title"); var notification_id = intent.GetStringExtra("notify_id"); int unique_id = 0; int.TryParse(notification_id.ToString(), out unique_id); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, unique_id, notIntent, PendingIntentFlags.CancelCurrent); var channel = new NotificationChannel(CHANNEL, "Notification", NotificationImportance.Default) { LockscreenVisibility = NotificationVisibility.Public }; int resourceId; resourceId = Resource.Drawable.local_rem_n; //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder(context) .SetContentIntent(contentIntent) .SetSmallIcon(Resource.Drawable.local_rem_n) .SetContentTitle(title) .SetContentText(message) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetChannelId(CHANNEL) .SetAutoCancel(true); //.SetVisibility(NotificationVisibility.Public); NotificationManager manager = (NotificationManager)Android.App.Application.Context.GetSystemService(Context.NotificationService); manager.CreateNotificationChannel(channel); var notification = builder.Build(); manager.Notify(unique_id, notification); }
async void SendNotificationAsync(object body, IDictionary <string, string> data) { var obj = (RemoteMessage.Notification)body; var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); foreach (var key in data.Keys) { intent.PutExtra(key, data[key]); } var pendingIntent = PendingIntent.GetActivity(this, MainActivity.NOTIFICATION_ID, intent, PendingIntentFlags.OneShot); Bitmap bitmap = null; //bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_user); using (var client = new HttpClient()) { var inputStream = await client.GetStreamAsync(data["icon_url"]); bitmap = BitmapFactory.DecodeStream(inputStream); } var notificationBuilder = new NotificationCompat.Builder(this, MainActivity.CHANNEL_ID) .SetSmallIcon(Resource.Drawable.ic_user) .SetContentTitle(obj.Title) .SetContentText(obj.Body) .SetWhen(DateTime.UtcNow.Ticks) .SetAutoCancel(true) .SetLargeIcon(bitmap) .SetStyle(new NotificationCompat.BigTextStyle().SetBigContentTitle(obj.Title)) .SetContentIntent(pendingIntent); var notificationManager = NotificationManagerCompat.From(this); notificationManager.Notify(MainActivity.NOTIFICATION_ID, notificationBuilder.Build()); }
public Notification CreateNotification(NotificationViewModel notificationViewModel) { PendingIntent resultPendingIntent = InitResultIntentBasingOnViewModel(notificationViewModel); NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationContext, _channelId) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentTitle(notificationViewModel.Title) // Set the title .SetContentText(notificationViewModel.Body) // the message to display. .SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent. .SetVibrate(null) .SetSound(null) .SetNumber(1) .SetCategory(NotificationCompat.CategoryMessage) .SetOnlyAlertOnce(true); // This is the icon to display if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { builder.SetColor(Resource.Color.colorPrimary); } builder.SetSmallIcon(Resource.Drawable.ic_notification); Notification notification = builder.Build(); bool isLowerVersion = Build.VERSION.SdkInt < BuildVersionCodes.O; bool isBadgeCounterSupported = ShortcutBadger.IsBadgeCounterSupported(NotificationContext); bool isMessage = notificationViewModel.Type == NotificationsEnum.NewMessageReceived; bool areNotificationsEnabled = NotificationManagerCompat.From(NotificationContext).AreNotificationsEnabled(); // Use Plugin for badges on older platforms that support them if (isLowerVersion && isBadgeCounterSupported && isMessage && areNotificationsEnabled) { ShortcutBadger.ApplyNotification(NotificationContext, notification, 1); } return(notification); }
public static async Task SendScheduledNotification(Context context, INotification notification) { var notificationIntent = new Intent(context, typeof(MainActivity)); var quotesRepository = ServiceLocator.Current.GetInstance <IQuotesRepository>(); var designQuote = await notification.GetDesignQuote(quotesRepository); notificationIntent.SetFlags(ActivityFlags.SingleTop); PendingIntent tappedPendingIntent = PendingIntent.GetActivity(context, Constants.TOUCH_NOTIFICATON_REQUEST_CODE, notificationIntent, PendingIntentFlags.UpdateCurrent); // Set action for share button Intent shareIntent = new Intent(context, typeof(AlarmReceiver)); shareIntent.SetAction(Constants.SHARE_NOTIFICATION_QUOTE_INTENT_ACTION); shareIntent.PutExtra(Constants.NOTIFICTAIONTYPE_KEY, notification.GetType().ToString()); // Add This notification to the intent just in case the user needs to share it shareIntent.PutExtra(Constants.SHARE_NOTIFICATION_QUOTE_INTENT_ACTION, JsonConvert.SerializeObject(designQuote)); PendingIntent shareNotificationPendingIntent = PendingIntent.GetBroadcast(context, Constants.SHARE_NOTIFICATION_REQUEST_CODE, shareIntent, PendingIntentFlags.CancelCurrent); var notificationBuilder = new NotificationCompat.Builder(context, Constants.NOTIFICTAIONTYPE_CHANNEL_ID) .SetContentTitle(designQuote.Author) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .SetSmallIcon(Resource.Drawable.notify_icon) .SetContentIntent(tappedPendingIntent) .SetContentText(designQuote.Quote) .SetPriority(NotificationCompat.PriorityDefault) .SetStyle(new NotificationCompat.BigTextStyle().BigText(designQuote.Quote)) .AddAction(Resource.Drawable.share, "Share Quote", shareNotificationPendingIntent) .SetContentText(designQuote.Quote) .SetAutoCancel(true); if (notification.GetNotificationType() == NotificationType.DailyAlarm) { notificationBuilder.SetSubText("Daily Quote"); } // Show the notification. var notificationManager = NotificationManagerCompat.From(Application.Context); notificationManager.Notify(Settings.NotificationCount++, notificationBuilder.Build()); }
public Task NotifyBigAsync(string v1, string v2) { //return Task.CompletedTask; return(Task.Factory.StartNew(() => { NotificationCompat.Builder builder = new NotificationCompat.Builder(_context, CHANNEL_ID) .SetSmallIcon(Resource.Drawable.planetside2logo) ; // Instantiate the Big Text style: //Notification.BigTextStyle textStyle = new Notification.BigTextStyle(); NotificationCompat.InboxStyle textStyle = new NotificationCompat.InboxStyle(); //fill with text textStyle.AddLine(v2); textStyle.AddLine(v2); // Set the summary text: textStyle.SetSummaryText(v1); // Plug this style into the builder: builder.SetStyle(textStyle); Notification notification = builder.Build(); // Get the notification manager: NotificationManager notificationManager = _context.GetSystemService(Context.NotificationService) as NotificationManager; if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { builder.SetVisibility(NotificationCompat.VisibilityPublic); } // Publish the notification: int notificationId = 0; notificationManager.Notify(notificationId, notification); })); }
/** * Create and show a simple notification containing the received FCM message. */ void SendNotification(string messageBody) { Android.Util.Log.Debug(TAG, "Location: SendNotification*************"); var notificationManager = NotificationManager.FromContext(this); //Check if notification channel exists and if not create one if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification); NotificationChannel notificationChannel = notificationManager.GetNotificationChannel(NOTIFICATION_CHANNEL_ID); if (notificationChannel == null) { notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_DESCRIPTION, NotificationImportance.Default); notificationChannel.LightColor = (int)ConsoleColor.Green; //Set if it is necesssary notificationChannel.EnableVibration(true); //Set if it is necesssary //notificationChannel.SetSound(defaultSoundUri, AudioAttributes.); notificationManager.CreateNotificationChannel(notificationChannel); } } var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity(this, 0 /* Request code */, intent, PendingIntentFlags.OneShot); //builder.setContentTitle() // required // .setSmallIcon() // required // .setContentText() // required // .setChannelId(id) // required for deprecated in API level >= 26 constructor .Builder(this) var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.icon) .SetContentTitle("Wootrix Message") .SetContentText(messageBody) .SetAutoCancel(true) .SetContentIntent(pendingIntent) .SetChannelId(NOTIFICATION_CHANNEL_ID); notificationManager.Notify(NOTIFICATION_ID /* ID of notification */, notificationBuilder.Build()); }
private void ButtonOnClick(object sender, EventArgs eventArgs) { // Pass the current button press count value to the next activity: Bundle valuesForActivity = new Bundle(); valuesForActivity.PutInt ("count", count); // When the user clicks the notification, SecondActivity will start up. Intent resultIntent = new Intent(this, typeof (SecondActivity)); // Pass some values to SecondActivity: resultIntent.PutExtras (valuesForActivity); // Construct a back stack for cross-task navigation: Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create (this); stackBuilder.AddParentStack (Java.Lang.Class.FromType(typeof(SecondActivity))); stackBuilder.AddNextIntent (resultIntent); // Create the PendingIntent with the back stack: PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent (0, PendingIntentFlags.UpdateCurrent); Notification.InboxStyle inboxStyle = new Notification.InboxStyle(); // Build the notification: NotificationCompat.Builder builder = new NotificationCompat.Builder (this) .SetAutoCancel (true) // Dismiss from the notif. area when clicked .SetContentIntent (resultPendingIntent) // Start 2nd activity when the intent is clicked. .SetContentTitle ("Button Clicked") // Set its title .SetNumber (count) // Display the count in the Content Info .SetSmallIcon(Resource.Drawable.Icon) // Display this icon .SetContentText (String.Format( "The button has been clicked {0} times.", count)); // The message to display. builder.SetDefaults((int)NotificationDefaults.Sound); // Finally, publish the notification: NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Notify(ButtonClickNotificationId, builder.Build()); // Increment the button press count: count++; }
/// <summary> /// Attach this method to <see cref="ParsePush.ParsePushNotificationReceived"/> to utilize a /// default handler for push notification. /// </summary> /// <remarks> /// This handler will try to get the launcher <see cref="Activity"/> and application icon, then construct a /// <see cref="Notification"/> out of them. It uses push payload's <c>title</c> and <c>alert</c> as the /// <see cref="Notification.ContentView"/> title and text. /// </remarks> /// <param name="sender"></param> /// <param name="args"></param> public static void DefaultParsePushNotificationReceivedHandler(object sender, ParsePushNotificationEventArgs args) { IDictionary <string, object> pushData = args.Payload; Context context = Application.Context; if (pushData == null || (!pushData.ContainsKey("alert") && !pushData.ContainsKey("title"))) { return; } string title = pushData.ContainsKey("title") ? pushData["title"] as string : ManifestInfo.DisplayName; string alert = pushData.ContainsKey("alert") ? pushData["alert"] as string : "Notification received."; string tickerText = title + ": " + alert; Random random = new Random(); int contentIntentRequestCode = random.Next(); Intent activityIntent = ManifestInfo.LauncherIntent; PendingIntent pContentIntent = PendingIntent.GetActivity(context, contentIntentRequestCode, activityIntent, PendingIntentFlags.UpdateCurrent); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .SetContentTitle(new Java.Lang.String(title)) .SetContentText(new Java.Lang.String(alert)) .SetTicker(new Java.Lang.String(tickerText)) .SetSmallIcon(ManifestInfo.PushIconId) .SetContentIntent(pContentIntent) .SetAutoCancel(true) .SetDefaults(NotificationDefaults.All); Notification notification = builder.Build(); NotificationManager manager = context.GetSystemService(Context.NotificationService) as NotificationManager; int notificationId = (int)DateTime.UtcNow.Ticks; try { manager.Notify(notificationId, notification); } catch (Exception) { // Some phones throw exception for unapproved vibration. notification.Defaults = NotificationDefaults.Lights | NotificationDefaults.Sound; manager.Notify(notificationId, notification); } }
private static void NotifyHeartRate(Context context, user_page userPage, int HR, HRStatus status) { // When the user clicks the notification, SecondActivity will start up. Intent resultIntent = new Intent(userPage, typeof(NotificationActivity)); // Passing HR and HRStatus to notification activity Bundle valuesForActivity = new Bundle(); valuesForActivity.PutInt("status", (int)status); valuesForActivity.PutInt("HR", HR); resultIntent.PutExtras(valuesForActivity); // Construct a back stack for cross-task navigation: TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context); stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(NotificationActivity))); stackBuilder.AddNextIntent(resultIntent); // Create the PendingIntent with the back stack: PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent | (int)PendingIntentFlags.OneShot); // Build the notification: NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .SetAutoCancel(true) // Dismiss from the notif. area when clicked .SetContentIntent(resultPendingIntent) // Start 2nd activity when the intent is clicked. .SetContentTitle("Is everything OK?") // Set its title .SetNumber(HR) // Display the HR in the Content Info .SetSmallIcon(Resource.Drawable.emptyheart_white) // Display this icon .SetContentText(string.Format( "Your heart beat {0} to {1} bpm.", status == HRStatus.Hypo ? "decreased dramaticaly" : status == HRStatus.Hyper ? "increased dramaticaly" : "is not stable and changed dramatically", HR)); // The message to display. // Finally, publish the notification: NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService); notificationManager.Notify(ButtonClickNotificationId, builder.Build()); }
/** * Posts a notification in the notification bar when a transition is detected. * If the user clicks the notification, control goes to the MainActivity. */ public static void SendNotification(Context context, string notificationDetails) { // Create an explicit content Intent that starts the main Activity. var notificationIntent = new Intent(context, typeof(MainActivity)); notificationIntent.PutExtra("from_notification", true); // Construct a task stack. var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(context); // Add the main Activity to the task stack as the parent. stackBuilder.AddParentStack(Class.FromType(typeof(MainActivity))); // Push the content Intent onto the stack. stackBuilder.AddNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. var notificationPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(context); // Define the notification settings. builder.SetSmallIcon(Resource.Mipmap.ic_launcher) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .SetLargeIcon(BitmapFactory.DecodeResource(context.Resources, Resource.Mipmap.ic_launcher)) .SetColor(Color.Red) .SetContentTitle("Location update") .SetContentText(notificationDetails) .SetContentIntent(notificationPendingIntent); // Dismiss notification once the user touches it. builder.SetAutoCancel(true); // Get an instance of the Notification manager var mNotificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager; // Issue the notification mNotificationManager.Notify(0, builder.Build()); }
private Notification CreateNotification() { #region Create Channel string channelId = "foreground"; string channelName = "foreground"; string channelDescription = "The foreground channel for notifications"; int _pendingIntentId = 1; NotificationManager _notificationManager; _notificationManager = (NotificationManager)Android.App.Application.Context.GetSystemService(Android.App.Application.NotificationService); if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var channelNameJava = new Java.Lang.String(channelName); var channel = new NotificationChannel(channelId, channelNameJava, NotificationImportance.Low) { Description = channelDescription, }; channel.EnableVibration(false); _notificationManager.CreateNotificationChannel(channel); } #endregion #region Create Notification Intent foregroundNotificationIntent = new Intent(Android.App.Application.Context, typeof(MainActivity)); PendingIntent pendingIntent = PendingIntent.GetActivity(Android.App.Application.Context, _pendingIntentId, foregroundNotificationIntent, PendingIntentFlags.OneShot); NotificationCompat.Builder builder = new NotificationCompat.Builder(Android.App.Application.Context, channelId) .SetContentIntent(pendingIntent) .SetContentTitle("ForegroundServiceApp") .SetContentText("Foreground service started") .SetOngoing(true) .SetColor(ActivityCompat.GetColor(Android.App.Application.Context, Resource.Color.colorAccent)) .SetLargeIcon(BitmapFactory.DecodeResource(Android.App.Application.Context.Resources, Resource.Drawable.xamagonBlue)) .SetSmallIcon(Resource.Drawable.xamagonBlue); var notification = builder.Build(); #endregion return(notification); }
public async void CheckNotifcationsForFavorites() { var favList = await StorageData.GetSeriesListFromFavoritesFile(); if (favList != null && favList.Count > 0) { foreach (SeriesDetails series in favList) { if (series.NextEpisode != null) { if (await WebData.GetDetailsForTVShowSeries(series.SeriesLink) is SeriesDetails updatedSeries) { if (await StorageData.SaveSeriesToFavoritesFile(updatedSeries)) { if (updatedSeries.NextEpisode != null && updatedSeries.NextEpisode.EpisodeStreamLinks != null && updatedSeries.NextEpisode.EpisodeStreamLinks.Count > 0) { await CreateNotificationChannel(); var activityIntent = new Intent(this.ApplicationContext, typeof(EpisodeDetailActivity)); activityIntent.PutExtra("itemLink", updatedSeries.NextEpisode.EpisodeLink); var stackBuilder = TaskStackBuilder.Create(this.ApplicationContext); stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(EpisodeDetailActivity))); stackBuilder.AddNextIntent(activityIntent); var resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)Android.App.PendingIntentFlags.UpdateCurrent); var builder = new NotificationCompat.Builder(this.ApplicationContext, CHANNEL_ID) .SetAutoCancel(true).SetContentIntent(resultPendingIntent) .SetContentTitle($"New Episode for {updatedSeries.Title}").SetSmallIcon(Resource.Drawable.icon) .SetContentText($"{updatedSeries.NextEpisode.EpisodeFullNameNumber}"); var notificationManager = NotificationManagerCompat.From(this.ApplicationContext); notificationManager.Notify(NOTIFICATION_ID++, builder.Build()); } } } } } } }
private void SendNotification(string messageBody, IDictionary <string, string> data) { var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.ClearTop); if (data != null) { foreach (var key in data.Keys) { intent.PutExtra(key, data[key]); } } var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); string channelId = "fcm_default_channel"; Android.Net.Uri defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification); var notificationBuilder = new NotificationCompat.Builder(this, channelId) .SetSmallIcon(Resource.Drawable.notification_icon) .SetStyle(new NotificationCompat.BigTextStyle() .BigText(messageBody)) .SetColor(Color.Black.ToArgb()) .SetContentText(messageBody) .SetAutoCancel(true) .SetSound(defaultSoundUri) .SetContentIntent(pendingIntent); var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); if (Build.VERSION.SdkInt >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, "Channel human readable title", NotificationManager.ImportanceDefault); notificationManager.CreateNotificationChannel(channel); } Random random = new Random(); int notifId = random.Next(9999 - 1000) + 1000; notificationManager.Notify(notifId, notificationBuilder.Build()); }
private Notification GetQuickUnlockNotification() { int grayIconResouceId = Resource.Drawable.ic_launcher_gray; if ((int)Android.OS.Build.VERSION.SdkInt < 16) { if (PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(GetString(Resource.String.QuickUnlockIconHidden_key), false)) { grayIconResouceId = Resource.Drawable.transparent; } } NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .SetSmallIcon(grayIconResouceId) .SetLargeIcon(MakeLargeIcon(BitmapFactory.DecodeResource(Resources, AppNames.NotificationLockedIcon))) .SetVisibility((int)Android.App.NotificationVisibility.Secret) .SetContentTitle(GetString(Resource.String.app_name)) .SetContentText(GetString(Resource.String.database_loaded_quickunlock_enabled, GetDatabaseName())); if ((int)Build.VERSION.SdkInt >= 16) { if (PreferenceManager.GetDefaultSharedPreferences(this) .GetBoolean(GetString(Resource.String.QuickUnlockIconHidden16_key), true)) { builder.SetPriority((int)NotificationPriority.Min); } else { builder.SetPriority((int)NotificationPriority.Default); } } // Default action is to show Kp2A builder.SetContentIntent(GetSwitchToAppPendingIntent()); // Additional action to allow locking the database builder.AddAction(Android.Resource.Drawable.IcLockLock, GetString(Resource.String.QuickUnlock_lockButton), PendingIntent.GetBroadcast(this, 0, new Intent(Intents.CloseDatabase), PendingIntentFlags.UpdateCurrent)); return(builder.Build()); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); Button button = FindViewById <Button>(Resource.Id.MyButton); button.Click += delegate { // Wear の入力画面を構築 // RemoteInput.Builder だと Android.RemoteInput と競合するのでフルで指定しています。 // 正式な書き方は不明です。。 var remoteInput = new Android.Support.V4.App.RemoteInput.Builder("Reply") .SetLabel(GetText(Resource.String.Reply)) // "Reply Label" .Build(); // pendingIntent で起動する Activity var intent = new Intent(this, typeof(StartActionActivity)); // Wear の Update を待つ処理 var replyPendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent); // Wear でスワイプ (Extender?) した際のアクション var replyAction = new NotificationCompat.Action.Builder( Android.Resource.Drawable.IcButtonSpeakNow, GetText(Resource.String.Reply), replyPendingIntent) // "リプライ" .AddRemoteInput(remoteInput) .Build(); // Wear の Extender を構築 var wealableExtender = new NotificationCompat.WearableExtender() .AddAction(replyAction); // Wear の Notification を構築 var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Android.Resource.Drawable.IcDialogAlert) .SetContentTitle(GetText(Resource.String.AlertTitle)) // "アラート" .SetContentText(GetText(Resource.String.AlertMessage)) // "左にスワイプしてください" .Extend(wealableExtender); // Notification を送る Activity を指定 var notificationManager = NotificationManagerCompat.From(this); // 実際に Notification を送る notificationManager.Notify(1, notificationBuilder.Build()); }; }
public override void OnCreate() { base.OnCreate(); //Set the default notification channel for your app when running Android Oreo if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O) { //Change for your default notification channel id here FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel"; //Change for your default notification channel name here FirebasePushNotificationManager.DefaultNotificationChannelName = "General"; } manager = (NotificationManager)MainApplication.Context.GetSystemService(MainApplication.NotificationService); //If debug you should reset the token each time. #if DEBUG FirebasePushNotificationManager.Initialize(this, true); #else FirebasePushNotificationManager.Initialize(this, false); #endif //Handle notification when app is closed here CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) => { Intent intent = new Intent(MainApplication.Context, typeof(MainActivity)); PendingIntent pendingIntent = PendingIntent.GetActivity(MainApplication.Context, pendingIntentId, intent, PendingIntentFlags.OneShot); var seed = Convert.ToInt32(Regex.Match(Guid.NewGuid().ToString(), @"\d+").Value); int id = new Random(seed).Next(000000000, 999999999); NotificationCompat.Builder builder = new NotificationCompat.Builder(MainApplication.Context, FirebasePushNotificationManager.DefaultNotificationChannelId) .SetContentIntent(pendingIntent) .SetContentTitle(Convert.ToString(p.Data["title"])) .SetContentText(Convert.ToString(p.Data["body"])) .SetLargeIcon(BitmapFactory.DecodeResource(MainApplication.Context.Resources, Resource.Drawable.icon)) .SetSmallIcon(Resource.Drawable.icon) .SetDefaults((int)NotificationDefaults.Sound | (int)NotificationDefaults.Vibrate); var notification = builder.Build(); manager.Notify(id, notification); }; }
public override void OnReceive(Context context, Intent intent) { Toast.MakeText(context, "Alarm showing now", ToastLength.Long).Show(); var med = intent.GetStringExtra("MedicineName"); int number = Convert.ToInt32(intent.GetStringExtra("NumberofTimes")); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var style = new NotificationCompat.BigTextStyle(); var check = intent.GetStringExtra("CheckValue"); NotificationManager manager = (NotificationManager)context.GetSystemService(Context.NotificationService); PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, intent, Android.App.PendingIntentFlags.UpdateCurrent); Android.Net.Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .SetSmallIcon(Resource.Drawable.Icon) .SetContentTitle("MedTrack Notification") .SetContentText(String.Format("It's time to take {0}- {1} times today", med, number)) .SetSound(alarmSound) .SetStyle(style) .SetAutoCancel(true) .SetContentIntent(resultPendingIntent); Notification notification = builder.Build(); manager.Notify(0, notification); if (number == 2 || (intent.GetStringExtra("evening") == "true")) { var intentNew = new Intent(context, typeof(RepeatEveningAlarmActivity)); intentNew.AddFlags(ActivityFlags.NewTask); context.StartActivity(intentNew); } else if ((number == 3) || ((number > 3 && (intent.GetStringExtra("check") == "true"))) || (number > 3 && (intent.GetStringExtra("afternoon") == "true"))) { var intentNew = new Intent(context, typeof(RepeatAfternoonAlarmActivity)); intentNew.AddFlags(ActivityFlags.NewTask); context.StartActivity(intentNew); } }
public static void GenerateNotification(string msg, string tag, Context context, Bundle extras = null) { lastNotification = DateTime.Now; Intent resultIntent = new Intent(context, typeof(MainActivity)); resultIntent.AddFlags(ActivityFlags.NewTask); if (extras != null) { resultIntent.PutExtras(extras); } TaskStackCompat stackBuilder = TaskStackCompat.Create(context); var classType = Java.Lang.Class.FromType(typeof(MainActivity)); stackBuilder.AddParentStack(classType); stackBuilder.AddNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .SetSmallIcon(Resource.Drawable.ic_launcher) .SetContentTitle("Chadder") .SetContentText(msg) .SetLights(255, 255, 255) .SetVibrate(vibrationPattern) .SetContentIntent(resultPendingIntent) .SetAutoCancel(true) .SetSound(Android.Net.Uri.Parse("android.resource://" + context.PackageName + "/" + Resource.Raw.ChadderSound)); var service = (NotificationManager)context.GetSystemService(NotificationService); service.CancelAll(); // Clear previous notifications (avoid duplicates) service.Notify(tag, NotificationID, mBuilder.Build()); }
public override void OnReceive (Context context, Intent intent) { if (MessagingService.REPLY_ACTION.Equals (intent.Action)) { int conversationId = intent.GetIntExtra (MessagingService.CONVERSATION_ID, -1); var reply = GetMessageText (intent); if (conversationId != -1) { Log.Debug (TAG, "Got reply (" + reply + ") for ConversationId " + conversationId); MessageLogger.LogMessage (context, "ConversationId: " + conversationId + " received a reply: [" + reply + "]"); using (var notificationManager = NotificationManagerCompat.From (context)) { var notificationBuilder = new NotificationCompat.Builder (context); notificationBuilder.SetSmallIcon (Resource.Drawable.notification_icon); notificationBuilder.SetLargeIcon (BitmapFactory.DecodeResource (context.Resources, Resource.Drawable.android_contact)); notificationBuilder.SetContentText (context.GetString (Resource.String.replied)); Notification repliedNotification = notificationBuilder.Build (); notificationManager.Notify (conversationId, repliedNotification); } } } }
void CreateNotification(string rejestracja) { // Instantiate the builder and set notification elements: var builder = new NotificationCompat.Builder(this) .SetContentTitle("Uwaga na samochód") .SetContentText("Twój samochód o rejestracji: " + rejestracja + " został otagowany") .SetSmallIcon(Resource.Drawable.car) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()); // Build the notification: Notification notification = builder.Build(); // Get the notification manager: NotificationManager notificationManager = GetSystemService(NotificationService) as NotificationManager; // Publish the notification: const int notificationId = 1; notificationManager.Notify(notificationId, notification); }
public void Show(string title, string message) { Intent intent = new Intent(AndroidApp.Context, typeof(MainActivity)); intent.PutExtra(TitleKey, title); intent.PutExtra(MessageKey, message); PendingIntent pendingIntent = PendingIntent.GetActivity(AndroidApp.Context, pendingIntentId++, intent, PendingIntentFlags.UpdateCurrent); NotificationCompat.Builder builder = new NotificationCompat.Builder(AndroidApp.Context, channelId) .SetContentIntent(pendingIntent) .SetContentTitle(title) .SetContentText(message) .SetLargeIcon(BitmapFactory.DecodeResource(AndroidApp.Context.Resources, Resource.Drawable.xamagonBlue)) .SetSmallIcon(Resource.Drawable.xamagonBlue) .SetDefaults((int)NotificationDefaults.Sound | (int)NotificationDefaults.Vibrate); Notification notification = builder.Build(); manager.Notify(messageId++, notification); }
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 defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification); var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification) .SetContentTitle("GCM Message") .SetContentText(message) .SetAutoCancel(true) .SetSound(defaultSoundUri) .SetContentIntent(pendingIntent); var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Notify(0, notificationBuilder.Build()); }
private void ShowNotification() { var resultIntent = new Intent(this, typeof(MainActivity)); resultIntent.AddFlags(ActivityFlags.ReorderToFront); var pendingIntent = PendingIntent.GetActivity(this, 0, resultIntent, PendingIntentFlags.UpdateCurrent); var notificationId = Resource.String.monkey_notification; var builder = new NotificationCompat.Builder(this) .SetSmallIcon(Resource.Drawable.Xamarin_Icon) .SetContentTitle(this.GetText(Resource.String.app_label)) .SetContentText(this.GetText(Resource.String.monkey_notification)) .SetContentIntent(pendingIntent) .SetAutoCancel(true); var notification = builder.Build(); var notificationManager = (NotificationManager)GetSystemService(NotificationService); notificationManager.Notify(notificationId, notification); }
public override void OnReceive (Context context, Intent intent) { var message = intent.GetStringExtra ("message"); var title = intent.GetStringExtra ("title"); var notIntent = new Intent (context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity (context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManagerCompat.From (context); var style = new NotificationCompat.BigTextStyle(); style.BigText(message); int resourceId; if (App.SelectedModel.VehicleType == "Car") resourceId = Resource.Drawable.Car; else if (App.SelectedModel.VehicleType == "Bike") resourceId = Resource.Drawable.Bike; else resourceId = Resource.Drawable.Other; var wearableExtender = new NotificationCompat.WearableExtender() .SetBackground(BitmapFactory.DecodeResource(context.Resources, resourceId)) ; //Generate a notification with just short text and small icon var builder = new NotificationCompat.Builder (context) .SetContentIntent (contentIntent) .SetSmallIcon (Resource.Drawable.ic_launcher) .SetContentTitle(title) .SetContentText(message) .SetStyle(style) .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetAutoCancel(true) .Extend(wearableExtender); var notification = builder.Build(); manager.Notify(0, notification); }
public override void OnReceive(Context context, Intent intent) { Toast.MakeText(context, "Alarm showing now", ToastLength.Long).Show(); var med = intent.GetStringExtra("MedicineName"); int number = Convert.ToInt32(intent.GetStringExtra("NumberofTimes")); var title = intent.GetStringExtra("title"); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var style = new NotificationCompat.BigTextStyle(); var check = intent.GetStringExtra("CheckValue"); NotificationManager manager = (NotificationManager)context.GetSystemService(Context.NotificationService); PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, intent, Android.App.PendingIntentFlags.UpdateCurrent); Android.Net.Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .SetSmallIcon(Resource.Drawable.Icon) .SetContentTitle("MedTrack Notification") .SetContentText(String.Format("It's time to take {0}- {1} times today", med, number)) .SetSound(alarmSound) .SetStyle(style) .SetAutoCancel(true) .SetContentIntent(resultPendingIntent); Notification notification = builder.Build(); manager.Notify(0, notification); if(number == 2 || (intent.GetStringExtra("evening") == "true")) { var intentNew = new Intent(context, typeof(RepeatEveningAlarmActivity)); intentNew.AddFlags(ActivityFlags.NewTask); context.StartActivity(intentNew); } else if((number ==3) || ((number >3 && (intent.GetStringExtra("check") == "true"))) || (number >3 && (intent.GetStringExtra("afternoon") == "true"))) { var intentNew = new Intent(context, typeof(RepeatAfternoonAlarmActivity)); intentNew.AddFlags(ActivityFlags.NewTask); context.StartActivity(intentNew); } }
/// <summary> /// Creates the notification. /// </summary> /// <param name="title">Title string.</param> /// <param name="message">Message string.</param> public static void CreateNotification(string title, string message) { try { NotificationCompat.Builder builder; Context context = Android.App.Application.Context; Intent resultIntent = context.PackageManager.GetLaunchIntentForPackage(context.PackageName); // Create a PendingIntent; we're only using one PendingIntent (ID = 0): const int PendingIntentId = 0; PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, PendingIntentId, resultIntent, PendingIntentFlags.OneShot); // Build the notification builder = new NotificationCompat.Builder(context) .SetAutoCancel(true) // dismiss the notification from the notification area when the user clicks on it .SetContentIntent(resultPendingIntent) // start up this activity when the user clicks the intent. .SetContentTitle(title) // Set the title .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .SetSmallIcon(context.ApplicationInfo.Icon) // This is the icon to display .SetContentText(message); // the message to display. var notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager; if (notificationId >= NotificationMaxId) { notificationId = 0; } notificationManager.Notify(notificationId++, builder.Build()); } catch (Java.Lang.Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}", CrossGeofence.Id, ex)); } catch (Exception ex1) { System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}", CrossGeofence.Id, ex1)); } }
protected override async void OnHandleIntent (Intent intent) { var download = new DbDownloadHelper (); var upload = new DbUploadHelper (); var newEntries = TimeManager.GetUnSynchedTimeeEntries (); var newLocations = GpsLocationManager.GetUnSynchedGpsLocations (); //getting jobs, codes and version await download.GetData(); await upload.UploadAll (newEntries, newLocations); //wait until is over var success = !download.DownloadFailed () && !upload.UploadFailed (); if (download.bCodes.Any () && download.nbCodes.Any () && download.jobs.Any ()) { var update = new DbUpdateHelper (); update.UpdateAll (download.jobs, download.bCodes, download.nbCodes, newEntries, newLocations); } string resultString = success ? "Synch Successfull" : "Synch Unsuccessfull"; string textString = download.message + " " + upload.message; var ic = success ? Resource.Drawable.sync : Resource.Drawable.unsynch; var pendingIntent = PendingIntent.GetActivity (this, 0, new Intent (this, typeof(MainActivity)), 0); var builder = new NotificationCompat.Builder (this) .SetAutoCancel (true) .SetContentIntent (pendingIntent) .SetContentTitle (resultString) .SetSmallIcon (ic) .SetContentInfo ("ETC Sync Notification") .SetContentText (textString); // Finally publish the notification var notificationManager = (NotificationManager)GetSystemService (NotificationService); notificationManager.Notify (0, builder.Build ()); Intent applicationIntent = new Intent (Forms.Context, typeof(MainActivity)); applicationIntent.AddFlags (ActivityFlags.NewTask); //Forms.Context.StartActivity (applicationIntent); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="intent"></param> public override void OnReceive(Context context, Intent intent) { var extra = intent.GetStringExtra(LocalNotificationKey); var notification = DeserializeNotification(extra); var builder = new NotificationCompat.Builder(Application.Context) .SetContentTitle(notification.Title) .SetContentText(notification.Body) .SetSmallIcon(notification.IconId) .SetAutoCancel(true); var resultIntent = LocalNotificationsImplementation.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); var notificationManager = NotificationManagerCompat.From(Application.Context); notificationManager.Notify(notification.Id, builder.Build()); }