Exemplo n.º 1
0
        /// <summary>
        /// The UpdateNotification
        /// </summary>
        /// <param name="title">The title<see cref="string"/></param>
        /// <param name="message">The message<see cref="string"/></param>
        /// <param name="bShowProgressBar">The bShowProgressBar<see cref="bool"/></param>
        public void UpdateNotification(string title, string message, bool bShowProgressBar)
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                if (title != null)
                {
                    bigTextStyle.SetBigContentTitle(prefix + " : " + title);
                }

                if (message != null)
                {
                    bigTextStyle.BigText(string.IsNullOrWhiteSpace(message) ? defaulttext : message);
                }

                mBuilder.SetProgress(0, 0, bShowProgressBar)
                .SetStyle(bigTextStyle)
                ;
            }
            else
            {
                if (title != null)
                {
                    mBuilder.SetContentTitle(prefix + " : " + title);
                }

                if (message != null)
                {
                    mBuilder.SetContentText(string.IsNullOrWhiteSpace(message) ? defaulttext : message);
                }
            }
            notificationManager.Notify(Notification_ID, mBuilder.Build());
        }
Exemplo n.º 2
0
		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);
		}
Exemplo n.º 3
0
        public void CreateLocalNotification(string titolo, string descrizione, int id, string rifordine, int idriga)
        {
            Context             ctx = Forms.Context;
            NotificationManager nm  = (NotificationManager)ctx.GetSystemService(Context.NotificationService);


            int notId = id + 9999;
            //esecuzione dell'intent
            //Yes intent
            Intent yesReceive = new Intent( );

            yesReceive.SetAction("YES_ACTION");
            Bundle yesBundle = new Bundle();

            yesBundle.PutInt("risp", 1);//This is the value I want to pass
            yesBundle.PutInt("id", id);
            yesBundle.PutString("ordine", rifordine);
            yesBundle.PutInt("idriga", idriga);
            yesReceive.PutExtras(yesBundle);
            PendingIntent pendingIntentYes = PendingIntent.GetBroadcast(ctx, notId, yesReceive, PendingIntentFlags.CancelCurrent);
            //no intent
            Intent noReceive = new Intent();

            noReceive.SetAction("NO_ACTION");
            Bundle noBundle = new Bundle();

            noBundle.PutInt("risp", 0);//This is the value I want to pass
            noBundle.PutInt("id", id);
            noReceive.PutExtras(noBundle);
            PendingIntent pendingIntentNo = PendingIntent.GetBroadcast(ctx, notId, noReceive, PendingIntentFlags.CancelCurrent);



            Android.Content.Res.Resources res = ctx.Resources;
            Bitmap bm = BitmapFactory.DecodeResource(res, FishOnLine.Droid.Resource.Drawable.icon);

            System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
            System.Text.Encoding iso  = System.Text.Encoding.GetEncoding("ISO-8859-1");
            string msg = iso.GetString(utf8.GetBytes(descrizione));

            NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
                                                 .SetPriority(NotificationCompat.PriorityMax)
                                                 .SetAutoCancel(true)
                                                 .SetLargeIcon(Bitmap.CreateScaledBitmap(bm, 80, 80, false))
                                                 .SetSmallIcon(Resource.Drawable.IcDialogInfo)
                                                 .SetContentTitle(titolo)
                                                 .SetContentText(msg)
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                 .SetOngoing(true)
                                                 .AddAction(Resource.Drawable.IcDelete, "Cancella", pendingIntentYes)
                                                 .AddAction(Resource.Drawable.IcMenuCloseClearCancel, "Chiudi", pendingIntentNo);
            NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
            bigTextStyle.SetBigContentTitle(titolo);
            bigTextStyle.BigText(descrizione);

            builder.SetStyle(bigTextStyle);


            nm.Notify(notId, builder.Build());
        }
Exemplo n.º 4
0
        /// <summary>
        /// The OnCreate
        /// </summary>
        public override void OnCreate()
        {
            context             = this;
            serialPortConnected = false;

            Intent intent = PackageManager
                            .GetLaunchIntentForPackage(PackageName)
                            .SetPackage(null)
                            .SetFlags(ActivityFlags.NewTask | ActivityFlags.ResetTaskIfNeeded);

            PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, intent, 0);

            exitPendingIntent = PendingIntent.GetBroadcast(this, 0, new Intent("LNG.CMRI.EXIT"), 0);

            bigTextStyle = new NotificationCompat.BigTextStyle();
            bigTextStyle.SetBigContentTitle(prefix);
            bigTextStyle.BigText(defaulttext);

            mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
                       .SetSmallIcon(Resource.Drawable.ic_gas_meter_free_icon_3)
                       .SetContentTitle("L+G CMRI")
                       .SetContentText("CMRI Service Started")
                       .SetStyle(bigTextStyle)
                       //.SetWhen(System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds())
                       //.SetAutoCancel(false)
                       .SetOnlyAlertOnce(true)
                       .SetProgress(0, 0, false)
                       .SetPriority((int)NotificationPriority.Max)
                       .SetOngoing(true)
                       .SetContentIntent(pendingIntent)
                       //.AddAction(Resource.Drawable.ic_mtrl_chip_close_circle, "EXIT APPLICATION", exitPendingIntent)
                       //.SetFullScreenIntent(pendingIntent,true)
            ;

            notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
            CreateNotificationChannel();

            mNotify = mBuilder.Build();

            StartForeground(Notification_ID, mNotify);

            SERVICE_CONNECTED = true;
            SetFilter();
            usbManager = (UsbManager)GetSystemService(Context.UsbService);

            FindSerialPortDevice();
        }
        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);
        }
Exemplo n.º 6
0
        private void btnSendNotificationWithMultiplePages_OnClick(object sender, EventArgs eventArgs)
        {
            // Specify the 'big view' content to display the long
            var bigStyle = new NotificationCompat.BigTextStyle();

            bigStyle.BigText("MUCH MUCH MUCH MUCH MUCH MORE MORE MORE MORE MORE MORE MORE MORE MORE MORE MORE MORE MORE TEXT!!");

            var builder = new NotificationCompat.Builder(Context);

            builder.SetContentTitle("Notification")
            .SetContentText("With Big Text")
            .SetLocalOnly(false)
            .SetSmallIcon(Resource.Drawable.icon10)
            .SetStyle(bigStyle);

            // Create a big text style for the second page
            var secondPageStyle = new NotificationCompat.BigTextStyle();

            secondPageStyle.SetBigContentTitle("Page 2")
            .BigText("A lot of text...");


            // Create second page notification
            Notification secondPageNotification = new NotificationCompat.Builder(Context)
                                                  .SetStyle(secondPageStyle)
                                                  .Build();

            // Extend the notification builder with the second page
            var notification = builder
                               .Extend(new NotificationCompat.WearableExtender()
                                       .AddPage(secondPageNotification))
                               .Build();


            NotificationManagerCompat.From(Context).Notify(119, notification);
        }
Exemplo n.º 7
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var intent        = new Intent(this, typeof(MainActivity));
            var contentIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.CancelCurrent);
            var manager       = NotificationManagerCompat.From(this);



            var title       = "I <3 C#";
            var message     = "Seattle Code Camp rocks!";
            var messageLong = "Seattle Code Camp is awesome, I can't wait to see the Xamarin.Forms Demo later! From what I hear it is going to be the best thing ever!";



            //Standard Notification
            FindViewById <Button>(Resource.Id.notification).Click += (sender, e) => {
                var style = new NotificationCompat.BigTextStyle();
                style.BigText(messageLong);

                //Generate a notification with just short text and small icon
                var builder = new NotificationCompat.Builder(this)
                              .SetContentIntent(contentIntent)
                              .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue)
                              .SetContentTitle(title)
                              .SetContentText(message)
                              .SetStyle(style)
                              .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                              .SetAutoCancel(true);


                var notification = builder.Build();
                manager.Notify(0, notification);
            };

            //Standard action with action
            FindViewById <Button>(Resource.Id.notification_action).Click += (sender, e) => {
                NotificationCompat.Action reply =
                    new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply,
                                                          "Reply", contentIntent)
                    .Build();

                var style = new NotificationCompat.BigTextStyle();
                style.BigText(messageLong);

                //Generate a notification with just short text and small icon
                var builder = new NotificationCompat.Builder(this)
                              .SetContentIntent(contentIntent)
                              .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue)
                              .SetContentTitle(title)
                              .SetContentText(message)
                              .SetStyle(style)
                              .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                              .SetAutoCancel(true)
                              .AddAction(reply);


                var notification = builder.Build();
                manager.Notify(0, notification);
            };


            //Special Button for Wear
            FindViewById <Button>(Resource.Id.notification_wear_action).Click += (sender, e) => {
                NotificationCompat.Action favorite =
                    new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_rating_favorite,
                                                          "Favorite", contentIntent)
                    .Build();

                NotificationCompat.Action reply =
                    new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply,
                                                          "Reply", contentIntent)
                    .Build();


                var style = new NotificationCompat.BigTextStyle();
                style.BigText(messageLong);

                //Generate a notification with just short text and small icon
                var builder = new NotificationCompat.Builder(this)
                              .SetContentIntent(contentIntent)
                              .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue)
                              .SetContentTitle(title)
                              .SetContentText(message)
                              .SetStyle(style)
                              .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                              .SetAutoCancel(true)
                              .AddAction(reply)
                              .Extend(new NotificationCompat.WearableExtender().AddActions(new [] { reply, favorite }));


                var notification = builder.Build();
                manager.Notify(0, notification);
            };

            //Custom Background
            FindViewById <Button>(Resource.Id.notification_wear_background).Click += (sender, e) => {
                var action = new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_rating_favorite,
                                                                   "Favorite", contentIntent)
                             .Build();

                var wearableExtender = new NotificationCompat.WearableExtender()
                                       .SetHintHideIcon(true)
                                       .SetBackground(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_background))
                                       .AddAction(action)
                ;

                var style = new NotificationCompat.BigTextStyle();
                style.BigText(messageLong);

                //Generate a notification with just short text and small icon
                var builder = new NotificationCompat.Builder(this)
                              .SetContentIntent(contentIntent)
                              .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue)
                              .SetContentTitle(title)
                              .SetContentText(message)
                              .SetStyle(style)
                              .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                              .SetAutoCancel(true)
                              .AddAction(Resource.Drawable.ic_stat_social_reply,
                                         "Reply", contentIntent)
                              .Extend(wearableExtender);


                var notification = builder.Build();
                manager.Notify(0, notification);
            };

            //Pages
            FindViewById <Button>(Resource.Id.notification_wear_pages).Click += (sender, e) => {
                // Create builder for the main notification
                var notificationBuilder =
                    new NotificationCompat.Builder(this)
                    .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue)
                    .SetContentTitle("Page 1")
                    .SetContentText("Short message")
                    .SetContentIntent(contentIntent);

                // Create a big text style for the second page
                var secondPageStyle = new NotificationCompat.BigTextStyle();
                secondPageStyle.SetBigContentTitle("Page 2")
                .BigText(messageLong);

                // Create second page notification
                var secondPageNotification = new NotificationCompat.Builder(this)
                                             .SetStyle(secondPageStyle)
                                             .Build();

                // Add second page with wearable extender and extend the main notification
                var twoPageNotification =
                    new NotificationCompat.WearableExtender()
                    .AddPage(secondPageNotification)
                    .Extend(notificationBuilder)
                    .Build();

                // Issue the notification
                manager.Notify(0, twoPageNotification);
            };

            //Stacked Notifications
            FindViewById <Button>(Resource.Id.notification_wear_stacked).Click += (sender, e) => {
                var wearableExtender =
                    new NotificationCompat.WearableExtender()
                    .SetBackground(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_background));

                // Build the notification, setting the group appropriately
                var notificaiton1 = new NotificationCompat.Builder(this)
                                    .SetContentTitle("New mail from James")
                                    .SetContentText(message)
                                    .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue)
                                    .SetGroup("group_1")
                                    .Extend(wearableExtender)
                                    .Build();


                var notification2 = new NotificationCompat.Builder(this)
                                    .SetContentTitle("New mail from ChrisNTR")
                                    .SetContentText("this is subject #1")
                                    .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue)
                                    .SetGroup("group_1")
                                    .Extend(wearableExtender)
                                    .Build();

                manager.Notify(0, notificaiton1);
                manager.Notify(1, notification2);
            };

            //Voice Input
            FindViewById <Button>(Resource.Id.notification_wear_voice).Click += (sender, e) => {
                var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(ExtraVoiceReply)
                                  .SetLabel("Reply")
                                  .SetChoices(new [] { "Yes", "No", "OK you win" })
                                  .Build();

                NotificationCompat.Action reply =
                    new NotificationCompat.Action.Builder(Resource.Drawable.ic_stat_social_reply,
                                                          "Reply", contentIntent)
                    .AddRemoteInput(remoteInput)

                    .Build();


                var wearableExtender = new NotificationCompat.WearableExtender();
                wearableExtender.AddAction(reply);


                //Generate a notification with just short text and small icon
                var builder = new NotificationCompat.Builder(this)
                              .SetContentIntent(contentIntent)
                              .SetSmallIcon(Resource.Drawable.ic_stat_hexagon_blue)
                              .SetContentTitle(title)
                              .SetContentText(message)
                              .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
                              .SetAutoCancel(true)
                              .AddAction(reply)
                              .Extend(wearableExtender);


                var notification = builder.Build();
                manager.Notify(0, notification);
            };

            var voiceReply = GetMessageText(Intent);

            if (!string.IsNullOrWhiteSpace(voiceReply))
            {
                FindViewById <TextView> (Resource.Id.textView1).Text = voiceReply;
            }
        }