Пример #1
0
        Notification buildCustomNotification(ServiceActions action)
        {
            PendingIntent pi    = PendingIntent.GetActivity(ApplicationContext, 0, new Intent(ApplicationContext, typeof(MainActivity)), PendingIntentFlags.CancelCurrent);
            PendingIntent play  = PendingIntent.GetService(ApplicationContext, 1, new Intent(ActionPlay), PendingIntentFlags.CancelCurrent);
            PendingIntent pause = PendingIntent.GetService(ApplicationContext, 2, new Intent(ActionPause), PendingIntentFlags.CancelCurrent);

            Android.App.Notification.Builder builder = new Notification.Builder(ApplicationContext);

            var myRemoteView = new RemoteViews(PackageName, Resource.Layout.Notification);

            builder.SetContent(myRemoteView);
            // if play
            if (action == ServiceActions.Play)
            {
                builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPlay);
                myRemoteView.SetTextViewText(Resource.Id.notifyTitle, "KQED 88.5FM LiveStream");
            }
            else if (action == ServiceActions.Pause)
            {
                builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPause);
                myRemoteView.SetTextViewText(Resource.Id.notifyTitle, "Paused: KQED 88.5FM LiveStream");
            }

            myRemoteView.SetOnClickPendingIntent(Resource.Id.notifyBtnPause, pause);
            myRemoteView.SetOnClickPendingIntent(Resource.Id.notifyBtnPlay, play);
            myRemoteView.SetOnClickPendingIntent(Resource.Id.notifyTitle, pi);
            myRemoteView.SetImageViewResource(Resource.Id.notifyImage, Resource.Drawable.KQED);

            return(builder.Notification);
        }
Пример #2
0
        void CreateNotification()
        {
            NotificationManager manager = Android.App.Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
            var builder = new Notification.Builder(Android.App.Application.Context);

            builder.SetContentTitle("Test Notification");
            builder.SetContentText("This is the body");
            builder.SetAutoCancel(true);
            builder.SetSmallIcon(Resource.Drawable.clipboard);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelId = "com.companyname.briefing.general";
                var channel   = new NotificationChannel(channelId, "General", NotificationImportance.Default);

                manager.CreateNotificationChannel(channel);

                builder.SetChannelId(channelId);
            }
            var resultIntent = Android.App.Application.Context.PackageManager.GetLaunchIntentForPackage(Android.App.Application.Context.PackageName);

            resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
            var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Android.App.Application.Context);

            stackBuilder.AddNextIntent(resultIntent);
            var resultPendingIntent =
                stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            builder.SetContentIntent(resultPendingIntent);

            manager.Notify(0, builder.Build());
        }
Пример #3
0
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            if (builder == null)
            {
                builder = new Notification.Builder(context);
            }

            builder.SetContentTitle(this.Title);
            if (this.TotalBytes > 0 && this.CurrentBytes != -1)
            {
                builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
            }
            else
            {
                builder.SetProgress(0, 0, true);
            }
            builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
            builder.SetContentInfo(context.GetString(Resource.String.time_remaining_notification, Helpers.GetTimeRemaining(this.TimeRemaining)));
            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return(builder.Notification);
        }
        protected override void OnMessage(Context context, Intent intent)
        {
            string message = string.Empty;

            // Extract the push notification message from the intent.
            if (intent.Extras.ContainsKey("message"))
            {
                message = intent.Extras.Get("message").ToString();
                var title = "Doctor Notification";

                // Create a notification manager to send the notification.
                var notificationManager =
                    GetSystemService(NotificationService) as NotificationManager;

                // Create a new intent to show the notification in the UI.
                PendingIntent contentIntent =
                    PendingIntent.GetActivity(context, 0,
                                              new Intent(this, typeof(MainActivity)), 0);

                // Create the notification using the builder.
                var builder = new Notification.Builder(context);
                builder.SetAutoCancel(true);
                builder.SetContentTitle(title);
                builder.SetContentText(message);
                builder.SetSmallIcon(Resource.Drawable.ic_launcher);
                builder.SetContentIntent(contentIntent);
                var notification = builder.Build();

                // Display the notification in the Notifications Area.
                notificationManager.Notify(1, notification);

                ShowPopUp(context, message);
            }
        }
Пример #5
0
        private void InitBlockChain()
        {
            if (BlockChainService.BlockChain == null)
            {
                BlockChainService.BlockChain = new BlockChainVotings();

                BlockChainService.BlockChain.CheckRoot();

                Task.Run(() =>
                {
                    BlockChainService.BlockChain.Start();
                });

                BlockChainService.BlockChain.NewVoting += (s, a) =>
                {
                    RunOnUiThread(() =>
                    {
                        var notificationManager     = GetSystemService(NotificationService) as NotificationManager;
                        PendingIntent contentIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(MainActivity)), 0);

                        var builder = new Notification.Builder(this);
                        builder.SetAutoCancel(true);
                        builder.SetContentTitle(Resources.GetString(Resource.String.newVoting));
                        builder.SetContentText(BlockChainService.BlockChain.GetVotingName(a.Data));
                        builder.SetSmallIcon(Resource.Drawable.Icon);
                        builder.SetContentIntent(contentIntent);
                        var notification = builder.Build();

                        notificationManager.Notify(1, notification);
                    });
                };
            }
        }
Пример #6
0
        private void NotifyToAutofill(string uri)
        {
            var intent = new Intent(this, typeof(AutofillActivity));

            intent.PutExtra("uri", uri);
            intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);

            var builder = new Notification.Builder(this);

            builder.SetSmallIcon(Resource.Drawable.notification_sm)
            .SetContentTitle(App.Resources.AppResources.BitwardenAutofillService)
            .SetContentText(App.Resources.AppResources.BitwardenAutofillServiceNotificationContent)
            .SetTicker(App.Resources.AppResources.BitwardenAutofillServiceNotificationContent)
            .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
            .SetContentIntent(pendingIntent);

            if (Build.VERSION.SdkInt > BuildVersionCodes.KitkatWatch)
            {
                builder.SetVisibility(NotificationVisibility.Secret)
                .SetColor(global::Android.Support.V4.Content.ContextCompat.GetColor(ApplicationContext,
                                                                                    Resource.Color.primary));
            }

            var notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.Notify(AutoFillNotificationId, builder.Build());
        }
Пример #7
0
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            var builder = new Notification.Builder(context);

            if (!string.IsNullOrEmpty(this.PausedText))
            {
                builder.SetContentTitle(this.PausedText);
                builder.SetContentText(string.Empty);
                builder.SetContentInfo(string.Empty);
            }
            else
            {
                builder.SetContentTitle(this.Title);
                if (this.TotalBytes > 0 && this.CurrentBytes != -1)
                {
                    builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
                }
                else
                {
                    builder.SetProgress(0, 0, true);
                }

                builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
                builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining)));
            }

            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return(builder.Notification);
        }
Пример #8
0
        protected override void OnMessage(Context context, Intent intent)
        {
            Console.WriteLine("Received Notification");

            //Push Notification arrived - print out the keys/values
            if (intent != null || intent.Extras != null)
            {
                var keyset = intent.Extras.KeySet();

                foreach (var key in intent.Extras.KeySet())
                {
                    Console.WriteLine("Key: {0}, Value: {1}", key, intent.Extras.GetString(key));
                }

                var msg = intent.GetStringExtra("message");

                var n = new Notification.Builder(context);
                n.SetSmallIcon(Android.Resource.Drawable.IcDialogAlert);
                n.SetContentTitle("InFridge Expiration Notice");
                n.SetTicker(msg);
                n.SetContentText(msg);

                var nm = NotificationManager.FromContext(context);
                nm.Notify(0, n.Build());
            }
        }
        protected override void OnMessage(Context context, Intent intent)
        {
            var currentActivity = Mvx.Resolve <IMvxAndroidCurrentTopActivity>().Activity;
            var message         = string.Empty;

            // Extract the push notification message from the intent.
            if (intent.Extras.ContainsKey("message"))
            {
                message = intent.Extras.Get("message").ToString();
                var title = "New item added:";

                // Create a notification manager to send the notification.
                var notificationManager =
                    GetSystemService(NotificationService) as NotificationManager;

                // Create a new intent to show the notification in the UI.
                var contentIntent =
                    PendingIntent.GetActivity(context, 0,
                                              new Intent(this, currentActivity.GetType()), 0);

                // Create the notification using the builder.
                var builder = new Notification.Builder(context);
                builder.SetAutoCancel(true);
                builder.SetContentTitle(title);
                builder.SetContentText(message);
                builder.SetSmallIcon(Resource.Drawable.ic_launcher);
                builder.SetContentIntent(contentIntent);
                var notification = builder.Build();

                // Display the notification in the Notifications Area.
                notificationManager.Notify(1, notification);
            }
        }
        //internal static bool
        void HandleNotification(string messageBody, string messageTitle)
        {
            var intent = new Intent(Forms.Context, typeof(MainActivity));

            intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            var pendingIntent = PendingIntent.GetActivity(Forms.Context, 0, intent, PendingIntentFlags.UpdateCurrent);


            var n = new Notification.Builder(Forms.Context);

            n.SetSmallIcon(Resource.Drawable.notification_template_icon_bg);
            n.SetLights(Android.Graphics.Color.Blue, 300, 1000);
            n.SetContentIntent(pendingIntent);
            n.SetContentTitle(messageTitle);
            n.SetTicker(messageBody);
            //n.SetLargeIcon(global::Android.Graphics.BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.icon));
            n.SetAutoCancel(true);
            n.SetContentText(messageBody);
            n.SetVibrate(new long[] {
                200,
                200,
                100,
            });

            var nm = NotificationManager.FromContext(Forms.Context);

            nm.Notify(0, n.Build());

            // Make call to Xamarin.Forms here with the event handler
        }
        protected override void OnMessage(Context context, Intent intent)
        {

            string message = string.Empty;

            // Extract the push notification message from the intent.
            if (intent.Extras.ContainsKey("message"))
            {
                message = intent.Extras.Get("message").ToString();
                var title = "Doctor Notification";

                // Create a notification manager to send the notification.
                var notificationManager =
                    GetSystemService(NotificationService) as NotificationManager;

                // Create a new intent to show the notification in the UI. 
                PendingIntent contentIntent =
                    PendingIntent.GetActivity(context, 0,
                    new Intent(this, typeof(MainActivity)), 0);

                // Create the notification using the builder.
                var builder = new Notification.Builder(context);
                builder.SetAutoCancel(true);
                builder.SetContentTitle(title);
                builder.SetContentText(message);
                builder.SetSmallIcon(Resource.Drawable.ic_launcher);
                builder.SetContentIntent(contentIntent);
                var notification = builder.Build();

                // Display the notification in the Notifications Area.
                notificationManager.Notify(1, notification);

                ShowPopUp(context, message);
            }
        }
Пример #12
0
        private void HandleEnterZone(Zone z)
        {
            Log.Debug(TAG, "Enter zone " + z.Name);

            Intent notificationIntent = new Intent(this, typeof(NotificationActivity));

            notificationIntent.PutExtra("zone_id", z.Id);
            notificationIntent.PutExtra("zone_name", z.Name);
            notificationIntent.PutExtra("zone_color", z.Color);
            notificationIntent.PutExtra("zone_alias", z.Alias);

            PendingIntent pendingIntent = PendingIntent.GetActivity(
                this,
                z.Id,
                notificationIntent,
                PendingIntentFlags.UpdateCurrent);

            Notification.Builder notificationBuilder = new Notification.Builder(this);
            notificationBuilder.SetSmallIcon(Resource.Drawable.elm_logo);
            notificationBuilder.SetContentTitle("New zone");
            notificationBuilder.SetContentText("You have entered zone '" + z.Name + "'");
            notificationBuilder.SetDefaults(NotificationDefaults.Sound);
            notificationBuilder.SetAutoCancel(true);
            notificationBuilder.SetContentIntent(pendingIntent);

            // Get an instance of the NotificationManager service
            NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

            //Build the notification and issues it with notification manager.
            notificationManager.Notify(z.Id, notificationBuilder.Build());
        }
Пример #13
0
        public void ShowNotification(Intent intent)
        {
            var id    = intent.GetIntExtra("id", 0);
            var title = intent.GetStringExtra("title");
            var body  = intent.GetStringExtra("message");

            var main_intent = new Intent(this, typeof(MainActivity));

            main_intent.PutExtra("type", "alarm");
            main_intent.PutExtra("id", id);

            var builder = new Notification.Builder(this);

            //builder.SetGroup("keep.grass");
            builder.SetTicker(title);
            builder.SetContentTitle(title);
            builder.SetContentText(body);
            builder.SetContentIntent
            (
                PendingIntent.GetActivity
                (
                    this,
                    id,
                    main_intent,
                    PendingIntentFlags.UpdateCurrent
                )
            );
            builder.SetSmallIcon(Resource.Drawable.icon);
            builder.SetLargeIcon(BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.icon));
            builder.SetDefaults(NotificationDefaults.All);
            builder.SetAutoCancel(true);

            ((NotificationManager)this.GetSystemService(NotificationService))
            .Notify(id, builder.Build());
        }
Пример #14
0
        public override void OnReceive(Context context, Intent intent)
        {
            //
            var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);

            //
            var resultIntent = new Intent(context, typeof(AfazerService));

            /*TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context);
             * stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(AfazerService)));
             * stackBuilder.AddNextIntent(resultIntent);*/

            //
            //PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);
            //
            var builder = new Notification.Builder(context);

            builder.SetAutoCancel(true);
            //builder.SetContentIntent(resultPendingIntent);
            builder.SetContentTitle(_title);
            builder.SetContentText(_description);
            builder.SetDefaults(NotificationDefaults.All);
            builder.SetSmallIcon(Resource.Drawable.icon);

            //
            notificationManager.Notify(100, builder.Build());
        }
Пример #15
0
        public async void Validate(string device, string correo, string contrasena)
        {
            string Result;
            var    ValidationResultTextView = FindViewById <TextView>(Resource.Id.ValidationResultTextView);
            var    Builder       = new Notification.Builder(this);
            var    ServiceClient = new SALLab07.ServiceClient();

            Console.WriteLine($"{correo} | {contrasena}");
            var SvcResult = await ServiceClient.ValidateAsync(
                correo,
                contrasena,
                device);

            Result = $"{SvcResult.Status}\n{SvcResult.Fullname}\n{SvcResult.Token}";

            if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Builder.SetContentTitle("Resultado de la Validación");
                Builder.SetContentText(Result);
                Builder.SetSmallIcon(Resource.Drawable.Icon);
                Builder.SetCategory(Notification.CategoryMessage);

                var ObjectNotification = Builder.Build();
                var Manager            = GetSystemService(
                    Android.Content.Context.NotificationService) as NotificationManager;
                Manager.Notify(0, ObjectNotification);
            }
            else
            {
                ValidationResultTextView.Text = Result;
            }
        }
        public void ShowNotification(string title, string content)
        {
            CreatNotificationChannel();
            Context context     = Android.App.Application.Context;
            var     intent      = getLaucherActivity();
            var     stackBuiler = TaskStackBuilder.Create(context);

            stackBuiler.AddNextIntent(intent);
            var pendingIntent = stackBuiler.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            if (builder == null)
            {
                builder = new Notification.Builder(context, "channel_ID");
            }

            builder.SetAutoCancel(true);
            builder.SetContentTitle(title);
            builder.SetContentIntent(pendingIntent);
            builder.SetContentText(content);
            //

            builder.SetSmallIcon(Resource.Drawable.ic_vol_type_tv_dark);
            // Resource.Drawable.ic_stat_button_click;

            Notification notification = builder.Build();

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

            notificationManager.Notify(NOTIFICATION_ID, notification);
        }
Пример #17
0
        protected override void OnCreate(Bundle bundle)
        {
            int i = 1;

            base.OnCreate(bundle);
            SetContentView(Resource.Layout.PaymentPage);
            Button paymentbtn = FindViewById <Button>(Resource.Id.paymentbtn);

            paymentbtn.Click += (o, e) =>
            {
                Toast.MakeText(this, "Confirmed", ToastLength.Short).Show();


                Notification.BigTextStyle textStyle = new Notification.BigTextStyle();

                textStyle.BigText("Your Code is 1234");
                // Set the summary text:
                textStyle.SetSummaryText("Enjoy :)");

                var notificationBuilder = new Notification.Builder(this)

                                          .SetContentTitle("Smarty's Notification")
                                          .SetContentText("Body goes here...........This is a big Notificaiton in Notification Tray")
                                          .SetAutoCancel(true)

                                          .SetPriority((int)NotificationPriority.Max)
                                          .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate | NotificationDefaults.Lights)
                                          .SetStyle(textStyle);

                if ((int)Android.OS.Build.VERSION.SdkInt >= 21)
                {
                    notificationBuilder.SetVisibility(NotificationVisibility.Public);
                    notificationBuilder.SetCategory(Notification.CategoryAlarm);
                    //notificationBuilder.SetSmallIcon(Resource.Drawable.transparentNotification);
                    notificationBuilder.SetSmallIcon(Resource.Drawable.logo);
                    //notificationBuilder.SetColor(Resources.GetColor(Resource));
                    notificationBuilder.SetVibrate(new long[] { 100, 200, 300 });
                }
                else
                {
                    notificationBuilder.SetSmallIcon(Resource.Drawable.logo);
                }

                var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
                notificationManager.Notify(i++, notificationBuilder.Build());
            };
        }
        private void Button_Click(object sender, EventArgs e)
        {
            notyBuilder = new Notification.Builder(this);

            notyBuilder.SetContentTitle("عنوان پیام");
            notyBuilder.SetContentText("متن پیام در اینجا قرار میگیرد");
            notyBuilder.SetSmallIcon(Resource.Drawable.noty_small_icon);
            notyBuilder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.noty_large_icon));
            notyBuilder.SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis());
            notyBuilder.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate);
            notyBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
            notyBuilder.SetAutoCancel(true);
            notyBuilder.SetPriority((int)NotificationPriority.High);

            if ((int)Android.OS.Build.VERSION.SdkInt >= 21)
            {
                notyBuilder.SetVisibility(NotificationVisibility.Public);
                notyBuilder.SetCategory(Notification.CategoryEmail);
            }



            #region BigTextStyle

            Notification.BigTextStyle textStyle = new Notification.BigTextStyle();
            string longTextMessage = "I went up one pair of stairs.";
            longTextMessage += " / Just like me. ";
            textStyle.BigText(longTextMessage);
            textStyle.SetSummaryText("The summary text goes here.");
            //notyBuilder.SetStyle(textStyle);

            #endregion

            #region InboxStyle

            var inboxStyle = new Notification.InboxStyle();
            inboxStyle.AddLine("Cheeta: Bananas on sale");
            inboxStyle.AddLine("George: Curious about your blog post");
            inboxStyle.AddLine("Nikko: Need a ride to Evolve?");
            inboxStyle.SetSummaryText("+2 more");

            notyBuilder.SetStyle(inboxStyle);

            #endregion

            #region imageStyle

            var imageStyle = new Notification.BigPictureStyle();
            imageStyle.BigPicture(BitmapFactory.DecodeResource(Resources, Resource.Drawable.facebook));
            imageStyle.SetSummaryText("+2 more");
            //notyBuilder.SetStyle(imageStyle);


            #endregion

            var notification = notyBuilder.Build();
            var notyManager  = GetSystemService(Context.NotificationService) as NotificationManager;
            notyManager.Notify(notyId, notification);
        }
        public void checkchange()
        {
            while (true)
            {
                IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
                foreach (IPAddress ip in localIPs)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        if (ipadre != ip.ToString())
                        {
                            servidor.Stop();
                            ipadre = ip.ToString();



                            servidor = new MultitubeWebServer(Android.OS.Environment.ExternalStorageDirectory.ToString(), 12345, ipadre, this);
                            var brandom = new Random();

                            Intent internado2                 = new Intent(this, typeof(serviciointerpreter23));
                            Intent internado3                 = new Intent(this, typeof(serviciointerpreter234));
                            var    pendingIntent3             = PendingIntent.GetService(ApplicationContext, brandom.Next(2000, 50000) + brandom.Next(2000, 50000), internado3, 0);
                            var    pendingIntent2             = PendingIntent.GetService(ApplicationContext, brandom.Next(2000, 50000) + brandom.Next(2000, 50000), internado2, 0);
                            Notification.Action       accion  = new Notification.Action(Resource.Drawable.drwaable, "Parar", pendingIntent2);
                            Notification.Action       accion2 = new Notification.Action(Resource.Drawable.drwaable, "Conectarse", pendingIntent3);
                            Notification.BigTextStyle textoo  = new Notification.BigTextStyle();
                            textoo.SetBigContentTitle("Stremeando en " + ipadre + ":12345");
                            textoo.SetSummaryText("Toque para parar de stremear su media");
                            textoo.BigText("Para conectarse introduzca " + ipadre + ":12345  " + "en su navegador o entre a multitubeweb.tk y toque conectar luego escanee el codigo que aparece al presionar el boton de + en multitubeweb.   al tocar parar se cierrar el servicio de streaming");


#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                            Notification.Builder nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
                            nBuilder.SetContentTitle("Stremeando en " + ipadre + ":12345");
                            nBuilder.SetContentText("Toque para parar de stremear su media");
                            nBuilder.SetStyle(textoo);
                            nBuilder.SetColor(Android.Graphics.Color.DarkRed.ToArgb());
                            nBuilder.SetOngoing(true);
                            //   nBuilder.SetContentIntent(pendingIntent2);
                            nBuilder.SetSmallIcon(Resource.Drawable.antena);
                            nBuilder.AddAction(accion);
                            nBuilder.AddAction(accion2);
                            Notification notification = nBuilder.Build();
                            StartForeground(193423456, notification);



                            if (CheckInternetConnection() && Constants.UseFirebase)
                            {
                                meterdata();
                            }
                        }
                    }
                }
                MultiHelper.ExecuteGarbageCollection();
                Thread.Sleep(5000);
            }
        }
        /// <summary>
        /// Show a local notification
        /// </summary>
        /// <param name="title">Title of the notification</param>
        /// <param name="body">Body or description of the notification</param>
        /// <param name="id">Id of the notification</param>
        public void Show(string title, string body, int id = 0)
        {
            var builder = new Notification.Builder(Application.Context);

            //var builder = new NotificationCompat.Builder(Application.Context);

            builder.SetContentTitle(title);
            builder.SetContentText(body);
            builder.SetAutoCancel(true);
            builder.SetPriority(Priority);
            builder.SetVibrate(Vibrate);


            if (NotificationIconId != 0)
            {
                builder.SetSmallIcon(NotificationIconId);
            }
            else
            {
                builder.SetSmallIcon(Resource.Drawable.plugin_lc_smallicon);
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelId = $"{_packageName}.general";
                //var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
                var channel = new NotificationChannel(channelId, "General", Importance);

                _manager.CreateNotificationChannel(channel);

                builder.SetChannelId(channelId);
            }

            var resultIntent = GetLauncherActivity();

            resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
            var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context);

            stackBuilder.AddNextIntent(resultIntent);
            var resultPendingIntent =
                stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            builder.SetContentIntent(resultPendingIntent);

            _manager.Notify(id, builder.Build());
        }
Пример #21
0
 public void notifier()
 {
     builder.SetContentText(disc_text.Text);
     builder.SetSmallIcon(Resource.Mipmap.ic_launcher);
     notify = builder.Build();
     notificationmanager = this.Activity.GetSystemService(Context.NotificationService) as NotificationManager;
     notificationmanager.Notify(notification_id, notify);
     disc_text.Text = "";
 }
Пример #22
0
        private void NotifyToAutofill(string uri, NotificationManager notificationManager)
        {
            if (notificationManager == null || string.IsNullOrWhiteSpace(uri))
            {
                return;
            }

            var now    = Java.Lang.JavaSystem.CurrentTimeMillis();
            var intent = new Intent(this, typeof(AutofillActivity));

            intent.PutExtra("uri", uri);
            intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);

            var notificationContent = Build.VERSION.SdkInt > BuildVersionCodes.KitkatWatch ?
                                      AppResources.BitwardenAutofillServiceNotificationContent :
                                      AppResources.BitwardenAutofillServiceNotificationContentOld;

            var builder = new Notification.Builder(this);

            builder.SetSmallIcon(Resource.Drawable.notification_sm)
            .SetContentTitle(AppResources.BitwardenAutofillService)
            .SetContentText(notificationContent)
            .SetTicker(notificationContent)
            .SetWhen(now)
            .SetContentIntent(pendingIntent);

            if (Build.VERSION.SdkInt > BuildVersionCodes.KitkatWatch)
            {
                builder.SetVisibility(NotificationVisibility.Secret)
                .SetColor(global::Android.Support.V4.Content.ContextCompat.GetColor(ApplicationContext,
                                                                                    Resource.Color.primary));
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                if (_notificationChannel == null)
                {
                    _notificationChannel = new NotificationChannel("bitwarden_autofill_service",
                                                                   AppResources.AutofillService, NotificationImportance.Low);
                    notificationManager.CreateNotificationChannel(_notificationChannel);
                }
                builder.SetChannelId(_notificationChannel.Id);
            }

            if (/*Build.VERSION.SdkInt <= BuildVersionCodes.N && */ _appSettings.AutofillPersistNotification)
            {
                builder.SetPriority(-2);
            }

            _lastNotificationTime = now;
            _lastNotificationUri  = uri;
            notificationManager.Notify(AutoFillNotificationId, builder.Build());

            builder.Dispose();
        }
Пример #23
0
        public void SentNoficationForNewInovoice(List <Customer> countNewНotifyNewInvoiceCustomers)
        {
            if (countNewНotifyNewInvoiceCustomers.Count > 0)
            {
                // Set up an intent so that tapping the notifications returns to this app:
                Intent intent = new Intent(this, typeof(MainActivity));

                // Create a PendingIntent;
                const int     pendingIntentId = 1;
                PendingIntent pendingIntent   =
                    PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot);


                // Instantiate the Inbox style:
                Notification.InboxStyle inboxStyle = new Notification.InboxStyle();

                //  Instantiate the builder and set notification elements:
                Notification.Builder bulideer = new Notification.Builder(this);

                bulideer.SetContentIntent(pendingIntent);
                bulideer.SetSmallIcon(Resource.Drawable.vik);

                // Set the title and text of the notification:
                bulideer.SetContentTitle("Нова фактура");
                //  bulideer.SetContentText("*****@*****.**");

                foreach (var item in countNewНotifyNewInvoiceCustomers)
                {
                    // Generate a message summary for the body of the notification:

                    //  if(item.DidGetNewInoviceToday == false)
                    //  {
                    string money = item.MoneyToPay.ToString("C", System.Globalization.CultureInfo.GetCultureInfo("bg-BG"));

                    inboxStyle.AddLine($"Аб. номер: {item.Nomer.ToString()}, {money}");

                    bulideer.SetContentText($"Аб. номер: {item.Nomer.ToString()}, {money}");

                    // item.DidGetNewInoviceToday = true;
                    //  }
                }
                // Plug this style into the builder:
                bulideer.SetStyle(inboxStyle);

                // Build the notification:
                Notification notification11 = bulideer.Build();

                // Get the notification manager:
                NotificationManager notificationManager1 =
                    GetSystemService(Context.NotificationService) as NotificationManager;

                // Publish the notification:
                const int notificationIdd = 1;
                notificationManager1.Notify(notificationIdd, notification11);
            }
        }
        /// <summary>
        ///     Updates IsPlaying action on Notification and toggle dismissable status
        /// </summary>
        /// <param name="playbackSpeed">Unused for Android</param>
        public void UpdateIsPlaying(float playbackSpeed = -1)
        {
            var isPlaying = AndroidAudioPlayer.SharedInstance.IsPlaying;

            if (isPlaying)
            {
                notificationBuilder.SetOngoing(true);
                notificationBuilder.SetSmallIcon(Android.Resource.Drawable.IcMediaPlay);
            }
            else
            {
                notificationBuilder.SetOngoing(false);
                notificationBuilder.SetSmallIcon(Android.Resource.Drawable.IcMediaPause);
            }

            notification            = notificationBuilder.Build();
            notification.Actions[1] = isPlaying ? pauseAction : playAction;
            Notify();
        }
        public void CreateSimplestNotification()
        {
            CreateNotificationChannel();
            var builder = new Notification.Builder(_lastChannelId);

            builder.SetContentTitle("Simple");
            builder.SetContentText("Notification");
            builder.SetSmallIcon("notify_icon_small");
            Notify(builder);
        }
        // Creates a new notification with a different visibility level.
        public Notification CreateNotification(NotificationVisibility visibility)
        {
            var builder = new Notification.Builder(Activity)
                          .SetContentTitle("Notification for Visibility metadata");

            builder.SetVisibility(visibility);
            builder.SetContentText(string.Format("Visibility : {0}",
                                                 NotificationVisibilities.GetDescription(visibility)));
            builder.SetSmallIcon(NotificationVisibilities.GetNotificationIconId(visibility));
            return(builder.Build());
        }
		// Creates a new notification with a different visibility level.
		public Notification CreateNotification(NotificationVisibility visibility)
		{
			var builder = new Notification.Builder (Activity)
				.SetContentTitle ("Notification for Visibility metadata");

			builder.SetVisibility (visibility);
			builder.SetContentText (string.Format ("Visibility : {0}", 
				NotificationVisibilities.GetDescription(visibility)));
			builder.SetSmallIcon (NotificationVisibilities.GetNotificationIconId (visibility));
			return builder.Build ();
		}
Пример #28
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

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

            sortingSpinner = FindViewById <Spinner>(Resource.Id.spinner1);

            tsumTsumDatabaseManager   = new TsumTsumDatabaseManager();
            tsumTsumBroadcastReceiver = new TsumTsumNotifcationBroadcastReceiver();

            toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);
            SetActionBar(toolbar);
            ActionBar.Title = GetString(Resource.String.ApplicationNameShort);

            sortingSpinner.ItemSelected += delegate
            {
                Settings.SetInt("sortingType", sortingSpinner.SelectedItemPosition);
                UpdateHeartView();
            };

            StartNotificationServiceIfNotRunning();

            if (!IsNotificationPermissionSet())
            {
                CreateAlert(
                    "No Permission",
                    "The required permissions are not set, do you want to set the setting now?",
                    "Yes",
                    (object sender, DialogClickEventArgs args) => { StartActivityForResult(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"), 0); }, // BEFORE: Android.Provider.Settings.ActionNotificationListenerSettings
                    "No",
                    (object sender, DialogClickEventArgs args) => { } // Deliberately empty!
                    );
            }

            CheckVersion(null, () =>
            {
                CreateAlert(
                    "New version available",
                    "A new version of the app is available, do you want to download it now?",
                    "Yes",
                    (object sender, DialogClickEventArgs args) => { StartActivity(new Intent(Intent.ActionView, global::Android.Net.Uri.Parse("http://tsumtsumhearttracker.pleduc.nl/download/newest/nl.pleduc.TsumTsumNotificationTracker-Signed.apk"))); },
                    "No",
                    (object sender, DialogClickEventArgs args) => { } // Deliberately empty!
                    );
            });

            Notification.Builder notificationBuilder = new Notification.Builder(this);
            notificationBuilder.SetContentTitle("Test");
            notificationBuilder.SetContentText("Test2");
            notificationBuilder.SetSmallIcon(Resource.Drawable.Icon);
            Notification notification = notificationBuilder.Build();
        }
Пример #29
0
        void SendNotification(MessaggioNotifica m)
        {
            var intent = new Intent (this, typeof(MainActivity));

            intent.AddFlags (ActivityFlags.ClearTop);

            var notifica = new Notification.Builder (this);
            switch (m.Tipo) {
            case "1":
                notifica.SetSmallIcon (Resource.Drawable.alert_1);
                break;
            case "2":
                notifica.SetSmallIcon (Resource.Drawable.alert_2);
                break;
            case "3":
                notifica.SetSmallIcon (Resource.Drawable.alert_3);
                break;
            default:
                notifica.SetSmallIcon (Resource.Drawable.InvioDoc);
                break;
            }

            if (m.Tipo == "4") {
                Messaggio mess = new Messaggio (m.Titolo, m.Messaggio);
                intent.PutExtra ("messaggio", JsonConvert.SerializeObject(mess));
            } else {
                intent.PutExtra ("commessanum", m.Commessa);
            }
            var pendingIntent = PendingIntent.GetActivity (this, 0, intent, PendingIntentFlags.OneShot);

            notifica.SetContentTitle (m.Titolo);
            notifica.SetContentText (m.Messaggio);
            notifica.SetAutoCancel (true);
            notifica.SetContentInfo (m.Commessa);
            notifica.SetSubText ("Commessa " + m.Commessa);
            notifica.SetVibrate (new long[] {100,200,100});
            notifica.SetSound (RingtoneManager.GetDefaultUri(RingtoneType.Notification));
            notifica.SetContentIntent (pendingIntent);
            var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
            notificationManager.Notify (0, notifica.Build());
        }
Пример #30
0
        private void CheckServerNotifications(Context pContext, string sClan, string sName)
        {
            XElement pResponse = null;
            //try
            //{
            string sPrevClan = Master.GetActiveClan();
            string sPrevUser = Master.GetActiveUserName();

            Master.SetActiveClan(sClan);
            Master.SetActiveUserName(sName);
            string sResponse = WebCommunications.SendPostRequest(Master.GetBaseURL() + Master.GetServerURL() + "GetUnseenNotifications", Master.BuildCommonBody(), true);

            pResponse = Master.ReadResponse(sResponse);
            Master.SetActiveClan(sPrevClan);
            Master.SetActiveUserName(sPrevUser);
            //}
            //catch (Exception e) { return; }

            if (pResponse.Element("Data") != null && pResponse.Element("Data").Element("Notifications").Value != "")
            {
                List <XElement> pNotifications = pResponse.Element("Data").Element("Notifications").Elements("Notification").ToList();
                foreach (XElement pNotification in pNotifications)
                {
                    string sContent  = pNotification.Value;
                    string sGameID   = pNotification.Attribute("GameID").Value;
                    string sGameName = pNotification.Attribute("GameName").Value;

                    Notification.Builder pBuilder = new Notification.Builder(pContext);
                    pBuilder.SetContentTitle(sClan + " - " + sGameName);
                    pBuilder.SetContentText(sContent);
                    pBuilder.SetSmallIcon(Resource.Drawable.Icon);
                    pBuilder.SetVibrate(new long[] { 200, 50, 200, 50 });
                    pBuilder.SetVisibility(NotificationVisibility.Public);
                    pBuilder.SetPriority((int)NotificationPriority.Default);

                    Intent pIntent = null;
                    if (sGameID.Contains("Zendo"))
                    {
                        pIntent = new Intent(pContext, typeof(ZendoActivity));
                    }
                    pIntent.SetAction(sGameID);
                    pIntent.PutExtra("GameName", sGameName);

                    pBuilder.SetContentIntent(PendingIntent.GetActivity(pContext, 0, pIntent, 0));
                    pBuilder.SetStyle(new Notification.BigTextStyle().BigText(sContent));

                    Notification        pNotif   = pBuilder.Build();
                    NotificationManager pManager = (NotificationManager)pContext.GetSystemService(Context.NotificationService);
                    pManager.Notify((int)Java.Lang.JavaSystem.CurrentTimeMillis(), pNotif);                     // using time to make different ID every time, so doesn't replace old notification
                    //pManager.Notify(DateTime.Now.Millisecond, pNotif); // using time to make different ID every time, so doesn't replace old notification
                }
            }
        }
Пример #31
0
        /// <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>
        public void Show(string title, string body)
        {
            var builder = new Notification.Builder(Application.Context);
            builder.SetContentTitle(title);
            builder.SetContentText(body);
            builder.SetSmallIcon(Resource.Drawable.Icon);

            var notification = builder.Build();

            var manager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;

            manager.Notify(0, notification);
        }
Пример #32
0
        /// <summary>
        /// 前台通知:避免被杀
        /// </summary>
        /// <param name="text"></param>
        void ServerNotification(string text)
        {
            PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, 0, _intent, 0);

            Notification.Builder builder = new Notification.Builder(Application.Context).SetContentIntent(pendingIntent);
            builder.SetAutoCancel(false).SetContentTitle("Alarm定时任务").SetContentText(text);
            builder.SetSmallIcon(Resource.Drawable.notification_template_icon_bg);

            notification = builder.Build();
            //_nm.Notify(1,notification);
            StartForeground(99999, notification);
            SetForeground(true);
        }
Пример #33
0
        private void SendNotification(string title, string text, int resourceIconId)
        {
            Notification.Builder notificationBuilder = new Notification.Builder(this);
            notificationBuilder.SetContentTitle(title);
            notificationBuilder.SetContentText(text);
            notificationBuilder.SetSmallIcon(resourceIconId);

            Notification notification = notificationBuilder.Build();

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

            notificationManager.Notify(++internalNotificationId, notification);
        }
Пример #34
0
        public void SentNotificationForReading(List <Customer> countНotifyReadingustomers)
        {
            if (countНotifyReadingustomers.Count > 0)
            {
                // Set up an intent so that tapping the notifications returns to this app:
                Intent intent = new Intent(this, typeof(MainActivity));

                // Create a PendingIntent;
                const int     pendingIntentId = 2;
                PendingIntent pendingIntent   =
                    PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.CancelCurrent);


                // Instantiate the Inbox style:
                Notification.InboxStyle inboxStyle = new Notification.InboxStyle();

                //  Instantiate the builder and set notification elements:
                Notification.Builder bulideer = new Notification.Builder(this);

                bulideer.SetSmallIcon(Resource.Drawable.vik);
                bulideer.SetContentIntent(pendingIntent);

                // Set the title and text of the notification:
                bulideer.SetContentTitle("Ден на отчитане");

                foreach (var cus in countНotifyReadingustomers)
                {
                    // Generate a message summary for the body of the notification:
                    string format = "dd.MM.yyyy";
                    string date   = cus.StartReportDate.ToString(format);

                    inboxStyle.AddLine($"Аб. номер: {cus.Nomer.ToString()}, {date}");

                    bulideer.SetContentText($"Аб. номер: {cus.Nomer.ToString()}, {date}");
                }

                // Plug this style into the builder:
                bulideer.SetStyle(inboxStyle);

                // Build the notification:
                Notification notification11 = bulideer.Build();

                // Get the notification manager:
                NotificationManager notificationManager1 =
                    GetSystemService(Context.NotificationService) as NotificationManager;

                // Publish the notification:
                const int notificationIdd = 2;
                notificationManager1.Notify(notificationIdd, notification11);
            }
        }
Пример #35
0
        //Notifications:
        private void notifyUser(String title, String message)
        {
            Notification.Builder builder = new Notification.Builder (activity)
                .SetContentTitle (title)

                .SetSubText (message)
                .SetContentText ("You will not be notified of leaving a region.");

            builder.SetSmallIcon (Resource.Drawable.green_button);
            builder.SetSound (Android.Media.RingtoneManager.GetDefaultUri (Android.Media.RingtoneType.Notification));
            Notification notification = builder.Build();

            NotificationManager notificationManager = activity.GetSystemService (Context.NotificationService) as NotificationManager;
            const int notificationId = 0;
            notificationManager.Notify (notificationId, notification);
        }
Пример #36
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


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

            txtView = (TextView)FindViewById(Resource.Id.tbNotificationInfo);
            //txtView = (TextView)FindViewById(Resource.Id.textView1);
            nReceiver = new NotificationReceiver();
            IntentFilter filter = new IntentFilter();
            filter.AddAction("com.dpwebdev.handsetfree.NOTIFICATION_LISTENER_EXAMPLE");
            RegisterReceiver(nReceiver, filter);

            // Get our button from the layout resource,
            // and attach an event to it
            Button createButton = FindViewById<Button>(Resource.Id.MyButton);
            Button catchButton = FindViewById<Button>(Resource.Id.catchNotification);

            createButton.Click += delegate
            {
                NotificationManager nManager = (NotificationManager)GetSystemService(NotificationListenerService.NotificationService);
                Notification.Builder ncomp = new Notification.Builder(this);
                ncomp.SetContentTitle("My Notification");
                ncomp.SetContentText("Notification Listener Service Example");
                ncomp.SetTicker("Notification Listener Service Example");
                ncomp.SetSmallIcon(Resource.Drawable.Icon);
                ncomp.SetAutoCancel(true);
                nManager.Notify(DateTime.Now.Millisecond, ncomp.Build());

                

            };

            catchButton.Click += delegate
            {
                
                Intent i = new Intent("com.dpwebdev.handsetfree.NOTIFICATION_LISTENER_SERVICE_EXAMPLE");
                i.PutExtra("command", "list");
                SendBroadcast(i);
            };

        }
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            var builder = new Notification.Builder(context);
            if (!string.IsNullOrEmpty(this.PausedText))
            {
                builder.SetContentTitle(this.PausedText);
                builder.SetContentText(string.Empty);
                builder.SetContentInfo(string.Empty);
            }
            else
            {
                builder.SetContentTitle(this.Title);
                if (this.TotalBytes > 0 && this.CurrentBytes != -1)
                {
                    builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
                }
                else
                {
                    builder.SetProgress(0, 0, true);
                }

                builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
                builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining)));
            }

            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return builder.Notification;
        }
Пример #38
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            base.OnStartCommand(intent, flags, startId);

            var notificationIntent = new Intent(BaseContext, typeof(MainActivity));
            notificationIntent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            var notifPendingIntent = PendingIntent.GetActivity(BaseContext, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);
            var notif = new Notification
            {
                ContentIntent = notifPendingIntent
            };

            Notification.Builder notifBuilder = new Notification.Builder(BaseContext);
            notifBuilder.SetContentIntent(notifPendingIntent);
            notifBuilder.SetWhen(JavaSystem.CurrentTimeMillis());
            notifBuilder.SetSmallIcon(Resource.Drawable.Knock);
            notifBuilder.SetContentTitle(Resources.GetString(Resource.String.ApplicationName));
            notifBuilder.SetContentText(Resources.GetString(Resource.String.NotifText));

            StartForeground(Process.MyPid(), notifBuilder.Build());
            
            //var notificationManager = (NotificationManager) BaseContext.GetSystemService(NotificationService);
            //notificationManager.Notify(Process.MyPid(), new Notification { ContentIntent = notifPendingIntent });

            RegisterListener();

            _wakeLockPartial?.Acquire();

            Status = ServiceStatus.STARTED;
            Log.Debug("WakeUpService", "Service start command.");
            return StartCommandResult.StickyCompatibility;
        }
Пример #39
0
        /// <summary>
        /// When we start on the foreground we will present a notification to the user
        /// When they press the notification it will take them to the main page so they can control the music
        /// </summary>
        void StartForeground ()
        {
            var intent = new Intent (ApplicationContext, typeof (MainActivity));
            intent.SetAction (Intent.ActionMain);
            intent.AddCategory (Intent.CategoryLauncher);
            ExtraUtils.PutSelectedTab (intent, (int) MainActivity.TabTitle.Player);

            var pendingIntent = PendingIntent.GetActivity (
                ApplicationContext,
                0,
                intent,
                PendingIntentFlags.UpdateCurrent
            );

            var notificationBuilder = new Notification.Builder (ApplicationContext);
            notificationBuilder.SetContentTitle (CurrentEpisode.Title);
            notificationBuilder.SetContentText (
                String.Format (
                    ApplicationContext.GetString (Resource.String.NotificationContentText),
                    ApplicationContext.GetString (Resource.String.ApplicationName)
                )
            );
            notificationBuilder.SetSmallIcon (Resource.Drawable.ic_stat_av_play_over_video);
            notificationBuilder.SetTicker (
                String.Format (
                    Application.GetString (Resource.String.NoticifationTicker),
                    CurrentEpisode.Title
                )
            );
            notificationBuilder.SetOngoing (true);
            notificationBuilder.SetContentIntent (pendingIntent);

            StartForeground (NotificationId, notificationBuilder.Build());
        }
Пример #40
0
        private void DisplayPushNotification(string title, string body)
        {
            Intent intent = new Intent(Application.Context, Settings.Instance.PushNotificationSettings.MainActivityType);
            intent.PutExtra(Constants.PushNotificationExtra, true);
            intent.SetFlags(Settings.Instance.PushNotificationSettings.ActivityFlags);
            // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
            const int pendingIntentId = 0;
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot);
            var notificationBuilder = new Notification.Builder(this).SetContentTitle(title)
                                                                    .SetContentText(body)
                                                                    .SetAutoCancel(true)
                                                                    .SetContentIntent(pendingIntent);
            if (Settings.Instance.PushNotificationSettings?.SmallIcon.HasValue ?? false)
            {
                notificationBuilder.SetSmallIcon(Settings.Instance.PushNotificationSettings.SmallIcon.Value);
            }

            var notificationManager = GetSystemService(NotificationService) as NotificationManager;
            notificationManager?.Notify(new Random().Next(100000), notificationBuilder.Build());
        }