private void BuildNotification(Notification.Action action)
        {
            var style  = new Notification.MediaStyle();
            var intent = new Intent(ApplicationContext, typeof(MediaPlayerService));

            intent.SetAction(ActionStop);
            var pendingIntent = PendingIntent.GetService(ApplicationContext, 1, intent, 0);

            Notification.Builder builder = new Notification.Builder(this)
                                           .SetSmallIcon(Resource.Mipmap.Icon)
                                           .SetContentTitle("Lock screen example")
                                           .SetContentText("Artist name")
                                           .SetDeleteIntent(pendingIntent)
                                           .SetStyle(style);

            builder.AddAction(GenerateAction(Android.Resource.Drawable.IcMediaPrevious, "Previous", ActionPrevious));
            builder.AddAction(GenerateAction(Android.Resource.Drawable.IcMediaRew, "Rew", ActionRewind));
            builder.AddAction(action);
            builder.AddAction(GenerateAction(Android.Resource.Drawable.IcMediaFf, "Fast forward", ActionFastForward));
            builder.AddAction(GenerateAction(Android.Resource.Drawable.IcMediaNext, "Next", ActionNext));

            style.SetShowActionsInCompactView(0, 2, 4);
            style.SetMediaSession(mediaSession.SessionToken);

            var notificationManager = (NotificationManager)GetSystemService(NotificationService);

            notificationManager.Notify(1, builder.Build());
        }
        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);
            }
        }
Exemple #3
0
 private static void AddPlayPauseActionCompat(
     Notification.Builder builder,
     Context context,
     bool isPlaying)
 {
     if (isPlaying)
     {
         builder.AddAction(NotificationHelper.GenerateActionCompat(context, Drawable.IcMediaPause, "Pause", MediaPlayerService.ActionPause));
     }
     else
     {
         builder.AddAction(NotificationHelper.GenerateActionCompat(context, Drawable.IcMediaPlay, "Play", MediaPlayerService.ActionPlay));
     }
 }
Exemple #4
0
        private void SetNotificationBar()
        {
            if (tracks.Count == 0)
            {
                return;
            }
            Intent playPause = new Intent("Pause");
            Intent previous  = new Intent("Previous");
            Intent next      = new Intent("Next");
            Intent loop      = new Intent("LoopBack");
            Intent details   = new Intent("Details");
            Intent cancel    = new Intent("Cancel");

            PendingIntent playPausePending = PendingIntent.GetBroadcast(this, 0, playPause, PendingIntentFlags.CancelCurrent);
            PendingIntent previousPending  = PendingIntent.GetBroadcast(this, 1, previous, PendingIntentFlags.CancelCurrent);
            PendingIntent nextPending      = PendingIntent.GetBroadcast(this, 2, next, PendingIntentFlags.CancelCurrent);
            PendingIntent cancelPending    = PendingIntent.GetBroadcast(this, 3, cancel, PendingIntentFlags.CancelCurrent);
            PendingIntent loopPending      = PendingIntent.GetBroadcast(this, 4, loop, PendingIntentFlags.CancelCurrent);
            PendingIntent OpenDetails      = PendingIntent.GetBroadcast(this, 10, details, PendingIntentFlags.CancelCurrent);
            string        artist           = Track_Finder.TrackFinder.GetArtistOfTrack(tracks[song].Path);

            using (Notification.Builder not = new Notification.Builder(this, "com.PapIndustries.PapMediaPlayerService"))
            {
                using (Notification.MediaStyle mediaStyle = new Notification.MediaStyle())
                {
                    not.SetSmallIcon(Resource.Drawable.Logo).SetContentTitle(tracks[song].Title).SetContentText(artist)
                    .SetOngoing(player.IsPlaying).SetStyle(mediaStyle.SetShowActionsInCompactView(0, 1, 2, 3, 4))
                    .AddAction(Resource.Drawable.Previous, "Previous", previousPending).SetContentIntent(OpenDetails)
                    .SetPriority((int)NotificationPriority.Max).SetCategory(Notification.CategoryService);
                    Bitmap icon = Track_Finder.TrackFinder.GetImageOfTrack(tracks[song].Path);
                    not.SetLargeIcon(icon ?? BitmapFactory.DecodeResource(Resources, Resource.Drawable.Note));

                    if (!player.IsPlaying)
                    {
                        not.AddAction(Resource.Drawable.Play, "Play", playPausePending);
                    }
                    else
                    {
                        not.AddAction(Resource.Drawable.Pause, "Pause", playPausePending);
                    }
                    not.AddAction(Resource.Drawable.Next, "Next", nextPending);
                    not.AddAction(manager.GetIcon(), manager.GetTitle(), loopPending);
                    not.AddAction(Resource.Drawable.ExitNotificationIcon, "Exit", cancelPending);
                    var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
                    notify = not.Build();
                    notificationManager.Notify(SERVICE_ID, notify);
                }
            }
        }
Exemple #5
0
        public void Notify(string title, string message, string itemId)
        {
            var context      = Application.Context;
            var resultIntent = new Intent(context, typeof(MainActivity));

            resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);

            var pending = PendingIntent.GetActivity(context, 0,
                                                    resultIntent,
                                                    PendingIntentFlags.CancelCurrent);

            var pickedUpIntent = new Intent("PickedUp");

            pickedUpIntent.PutExtra("itemId", itemId);
            var pendingPickedUpIntent = PendingIntent.GetBroadcast(context, 0, pickedUpIntent, PendingIntentFlags.CancelCurrent);
            var builder =
                new Notification.Builder(context)
                .SetContentTitle(title)
                .SetContentText(message)
                .SetSmallIcon(Resource.Drawable.icon)
                .SetDefaults(NotificationDefaults.All)
                .SetVisibility(NotificationVisibility.Public);

            builder.SetContentIntent(pending);
            var pickedUpAction = new Notification.Action(Resource.Drawable.abc_btn_check_material, "Picked Up", pendingPickedUpIntent);

            builder.AddAction(pickedUpAction);

            var notification = builder.Build();

            notification.Flags = NotificationFlags.AutoCancel;
            var manager = NotificationManager.FromContext(context);

            manager.Notify(1337, notification);
        }
Exemple #6
0
        private void CreateBuilder()
        {
            Notification.Builder builder        = new Notification.Builder(context);
            Intent        previousIntent        = new Intent("music-controls-previous");
            PendingIntent previousPendingIntent = PendingIntent.GetBroadcast(context, 1, previousIntent, 0);

            builder.AddAction(0, "", previousPendingIntent);


            Intent        nextIntent        = new Intent("music-controls-next");
            PendingIntent nextPendingIntent = PendingIntent.GetBroadcast(context, 1, nextIntent, 0);

            builder.AddAction(1, "", nextPendingIntent);


            this.builder = builder;
        }
Exemple #7
0
        private static void CreateNotificationMediaActions()
        {
            Intent stopIntent = new Intent("ACTION_MEDIA_BUTTON");

            stopIntent.SetClass(Application.Context, typeof(BluetoothRemoteControlReciever));
            stopIntent.PutExtra(Intent.ExtraKeyEvent, new KeyEvent(KeyEventActions.Down, Keycode.MediaStop));
            PendingIntent stopPendingIntent = PendingIntent.GetBroadcast(Application.Context, 3, stopIntent, PendingIntentFlags.UpdateCurrent);

            Notification.Action stopAction = new Notification.Action(Resource.Drawable.ic_cancel_blue, string.Empty, stopPendingIntent);
            builder.AddAction(stopAction);
        }
Exemple #8
0
    internal static void StartNotification(
        Context context,
        MediaMetadata mediaMetadata,
        AndroidMedia.Session.MediaSession mediaSession,
        Object largeIcon,
        bool isPlaying)
    {
        var pendingIntent = PendingIntent.GetActivity(
            context,
            0,
            new Intent(context, typeof(MainActivity)),
            PendingIntentFlags.UpdateCurrent);
        MediaMetadata currentTrack = mediaMetadata;

        MediaStyle style = new MediaStyle();

        style.SetMediaSession(mediaSession.SessionToken);

        var builder = new Notification.Builder(context, CHANNEL_ID)
                      .SetStyle(style)
                      .SetContentTitle(currentTrack.GetString(MediaMetadata.MetadataKeyTitle))
                      .SetContentText(currentTrack.GetString(MediaMetadata.MetadataKeyArtist))
                      .SetSubText(currentTrack.GetString(MediaMetadata.MetadataKeyAlbum))
                      .SetSmallIcon(Resource.Drawable.player_play)
                      .SetLargeIcon(largeIcon as Bitmap)
                      .SetContentIntent(pendingIntent)
                      .SetShowWhen(false)
                      .SetOngoing(isPlaying)
                      .SetVisibility(NotificationVisibility.Public);

        builder.AddAction(NotificationHelper.GenerateActionCompat(context, Drawable.IcMediaPrevious, "Previous", MediaPlayerService.ActionPrevious));
        AddPlayPauseActionCompat(builder, context, isPlaying);
        builder.AddAction(NotificationHelper.GenerateActionCompat(context, Drawable.IcMediaNext, "Next", MediaPlayerService.ActionNext));
        style.SetShowActionsInCompactView(0, 1, 2);

        NotificationManagerCompat.From(context).Notify(NotificationId, builder.Build());
    }
Exemple #9
0
        void ShowNotification()
        {
            currentBuilder = new Notification.Builder(this)
                             .SetContentTitle(Resources.GetString(Resource.String.notification_title_biking))
                             .SetContentText(Resources.GetString(Resource.String.notification_subtitle_biking))
                             .SetSmallIcon(Resource.Drawable.icon_notification)
                             .SetUsesChronometer(true)
                             .SetOngoing(true);
            var pending = PendingIntent.GetService(
                this,
                Resource.Id.bikr_intent_notification,
                new Intent(FinishTripAction, Android.Net.Uri.Empty, this, typeof(BikrActivityService)),
                PendingIntentFlags.UpdateCurrent
                );

            currentBuilder.AddAction(Resource.Drawable.ic_notif_stop,
                                     Resources.GetString(Resource.String.stop_notif_action),
                                     pending);
            StartForeground(Resource.Id.bikr_notification, currentBuilder.Build());
        }
        void AddPlayPauseAction(Notification.Builder builder)
        {
            LogHelper.Debug(Tag, "updatePlayPauseAction");
            string        label;
            int           icon;
            PendingIntent intent;

            if (playbackState.State == PlaybackStateCode.Playing)
            {
                label  = service.GetString(Resource.String.label_pause);
                icon   = Resource.Drawable.ic_pause_white_24dp;
                intent = pauseIntent;
            }
            else
            {
                label  = service.GetString(Resource.String.label_play);
                icon   = Resource.Drawable.ic_play_arrow_white_24dp;
                intent = playIntent;
            }
            builder.AddAction(new Notification.Action(icon, label, intent));
        }
Exemple #11
0
        public override void OnMessageReceived(IMessageEvent messageEvent)
        {
            string path = messageEvent.Path;

            if (path.Equals(Constants.QUIZ_EXITED_PATH))
            {
                ((NotificationManager)GetSystemService(NotificationService)).CancelAll();
            }
            if (path.Equals(Constants.QUIZ_ENDED_PATH) || path.Equals(Constants.QUIZ_EXITED_PATH))
            {
                var dataMap      = DataMap.FromByteArray(messageEvent.GetData());
                int numCorrect   = dataMap.GetInt(Constants.NUM_CORRECT);
                int numIncorrect = dataMap.GetInt(Constants.NUM_INCORRECT);
                int numSkipped   = dataMap.GetInt(Constants.NUM_SKIPPED);

                var builder = new Notification.Builder(this)
                              .SetContentTitle(GetString(Resource.String.quiz_report))
                              .SetSmallIcon(Resource.Drawable.ic_launcher)
                              .SetLocalOnly(true);
                var quizReportText = new SpannableStringBuilder();
                AppendColored(quizReportText, numCorrect.ToString(), Resource.Color.dark_green);
                quizReportText.Append(" " + GetString(Resource.String.correct) + "\n");
                AppendColored(quizReportText, numIncorrect.ToString(), Resource.Color.dark_red);
                quizReportText.Append(" " + GetString(Resource.String.incorrect) + "\n");
                AppendColored(quizReportText, numSkipped.ToString(), Resource.Color.dark_yellow);
                quizReportText.Append(" " + GetString(Resource.String.skipped) + "\n");

                builder.SetContentText(quizReportText);
                if (!path.Equals(Constants.QUIZ_EXITED_PATH))
                {
                    builder.AddAction(Resource.Drawable.ic_launcher,
                                      GetString(Resource.String.reset_quiz), GetResetQuizPendingIntent());
                }
                ((NotificationManager)GetSystemService(NotificationService))
                .Notify(QUIZ_REPORT_NOTIF_ID, builder.Build());
            }
        }
        public void PostNotification(int notifid, string title, string text, bool autoCancellable, NotificationImportance notificationImportance)
        {
            NotificationChannel notificationChannel = new NotificationChannel("livedisplaynotificationchannel", "LiveDisplay", notificationImportance);

            notificationManager.CreateNotificationChannel(notificationChannel);
            Notification.Builder builder = new Notification.Builder(Application.Context, "livedisplaynotificationchannel");
            builder.SetContentTitle(title);
            builder.SetContentText(text);
            builder.SetAutoCancel(autoCancellable);
            builder.SetSmallIcon(Resource.Drawable.ic_stat_default_appicon);
            builder.SetAutoCancel(true);

            RemoteInput remoteInput = new RemoteInput.Builder("test1").SetLabel("This is the place where you write").Build();

            Intent intent = new Intent(Application.Context, Java.Lang.Class.FromType(typeof(SettingsActivity)));

            PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, 35, intent, PendingIntentFlags.UpdateCurrent);

            Notification.Action.Builder action = new Notification.Action.Builder(Resource.Drawable.ic_stat_default_appicon, "Answer", pendingIntent).AddRemoteInput(remoteInput);

            builder.AddAction(action.Build());

            notificationManager.Notify(notifid, builder.Build());
        }
		private static void ShowNativeNotification(Common.Message message, string notificationId, ButtonSet buttonSet = null, string alertTextOverride = null)
		{
			var nativeNotificationId = new Random().Next();

			// Setup intent to launch application
			var context = Application.Context;

			// Build the notification
			var builder = new Notification.Builder(context)
				.SetContentTitle(message.SenderDisplayName)
				.SetSmallIcon(Resource.Drawable.donky_notification_small_icon_simple_push)
				.SetContentText(alertTextOverride ?? message.Body)
				.SetVibrate(new[] { 0L, 100L })
			    .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));

			var pushMessage = message as SimplePushMessage;
			if (pushMessage != null && buttonSet != null && buttonSet.ButtonSetActions.Any())
			{
				builder.SetAutoCancel(false);
				// Jelly Bean + above supports multiple actions
				if (buttonSet.ButtonSetActions.Count == 2
				    && Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean)
				{
					foreach (var action in buttonSet.ButtonSetActions)
					{
						builder.AddAction(0,
							action.Label,
							CreateIntentForAction(context, nativeNotificationId, 
								notificationId, action, pushMessage,
								buttonSet));
					}
				}
				else
				{
					builder.SetContentIntent(CreateIntentForAction(context, nativeNotificationId, 
						notificationId, buttonSet.ButtonSetActions[0], 
						pushMessage, buttonSet));
				}
			}
			else
			{
				var intent = CreateIntentForBasicPush(context, nativeNotificationId, notificationId);
				builder.SetContentIntent(intent)
					.SetAutoCancel(true);
			}

            // bug
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                builder.SetCategory(Notification.CategoryMessage)
                    .SetPriority((int) NotificationPriority.High)
                    .SetVisibility(NotificationVisibility.Public);

                // this is for a Heads-Up Notification (Out of App Notification)
                var push = new Intent();
                push.AddFlags(ActivityFlags.NewTask);
                push.SetClass(context, Java.Lang.Class.FromType(context.GetType()));
                var fullScreenPendingIntent = PendingIntent.GetActivity(context, 0,
                    push, PendingIntentFlags.CancelCurrent);
                builder
                    .SetContentText(alertTextOverride ?? message.Body)
                    .SetFullScreenIntent(fullScreenPendingIntent, true);

            }

			var notification = builder.Build();

			notification.LedARGB = Color.White;
			notification.Flags |= NotificationFlags.ShowLights;
			notification.LedOnMS = 200;
			notification.LedOffMS = 2000;

			var notificationManager = (NotificationManager) context.GetSystemService(Context.NotificationService);
			notificationManager.Notify(nativeNotificationId, notification);
		}
Exemple #14
0
        /// <summary>
        /// Updates the foreground service notification builder, so that it reflects the enrollment status and participation level of the user.
        /// </summary>
        public void UpdateForegroundServiceNotificationBuilder()
        {
            SensusServiceHelper serviceHelper = SensusServiceHelper.Get();

            // the service helper will be null when this method is called from OnCreate. set some generic text until
            // the service helper has a chance to load, at which time this method will be called again and we'll update
            // the notification with more detailed information.
            if (serviceHelper == null)
            {
                _foregroundServiceNotificationBuilder.SetContentTitle("Starting...");
                _foregroundServiceNotificationBuilder.SetContentText("Tap to Open Sensus.");
            }
            // after the service helper has been initialized, we'll have more information about the studies.
            else
            {
                int numRunningStudies = serviceHelper.RegisteredProtocols.Count(protocol => protocol.State == ProtocolState.Running);

                _foregroundServiceNotificationBuilder.SetContentTitle("You are participating in " + numRunningStudies + " " + (numRunningStudies == 1 ? "study" : "studies") + ".");

                string contentText = "";

                // although the number of studies might be greater than 0, the protocols might not yet be started (e.g., after starting sensus).
                // also, only display the percentage if at least one protocol is configured to display it.
                List <Protocol> protocolsToAverageParticipation = serviceHelper.GetRunningProtocols()
                                                                  .Where(runningProtocol => runningProtocol.DisplayParticipationPercentageInForegroundServiceNotification).ToList();
                if (protocolsToAverageParticipation.Count > 0)
                {
                    double avgParticipation = protocolsToAverageParticipation.Average(protocol => protocol.Participation) * 100;
                    contentText += "Your overall participation level is " + Math.Round(avgParticipation, 0) + "%. ";
                }

                contentText += "Tap to open Sensus.";

                _foregroundServiceNotificationBuilder.SetContentText(contentText);

                // allow user to pause/resume data collection via the notification
                if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
                {
                    // clear current actions
                    _foregroundServiceNotificationBuilder.SetActions();

                    // add pause action
                    int numPausableProtocols = serviceHelper.RegisteredProtocols.Count(protocol => protocol.State == ProtocolState.Running && protocol.AllowPause);
                    if (numPausableProtocols > 0)
                    {
                        Intent        pauseActionIntent        = new Intent(FOREGROUND_SERVICE_NOTIFICATION_ACTION_PAUSE);
                        PendingIntent pauseActionPendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, pauseActionIntent, PendingIntentFlags.CancelCurrent);
                        string        pauseActionTitle         = "Pause " + numPausableProtocols + " " + (numPausableProtocols == 1 ? "study" : "studies") + ".";
                        _foregroundServiceNotificationBuilder.AddAction(new Notification.Action(Resource.Drawable.ic_media_pause_light, pauseActionTitle, pauseActionPendingIntent));  // note that notification actions no longer display the icon
                    }

                    // add resume action
                    int numPausedStudies = serviceHelper.RegisteredProtocols.Count(protocol => protocol.State == ProtocolState.Paused);
                    if (numPausedStudies > 0)
                    {
                        Intent        resumeActionIntent        = new Intent(FOREGROUND_SERVICE_NOTIFICATION_ACTION_RESUME);
                        PendingIntent resumeActionPendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, resumeActionIntent, PendingIntentFlags.CancelCurrent);
                        string        resumeActionTitle         = "Resume " + numPausedStudies + " " + (numPausedStudies == 1 ? "study" : "studies") + ".";
                        _foregroundServiceNotificationBuilder.AddAction(new Notification.Action(Resource.Drawable.ic_media_play_light, resumeActionTitle, resumeActionPendingIntent));  // note that notification actions no longer display the icon
                    }
                }
            }
        }
		public override void OnMessageReceived (IMessageEvent messageEvent)
		{
			string path = messageEvent.Path;
			if (path.Equals (Constants.QUIZ_EXITED_PATH)) {
				((NotificationManager)GetSystemService (NotificationService)).CancelAll ();
			}
			if (path.Equals (Constants.QUIZ_ENDED_PATH) || path.Equals (Constants.QUIZ_EXITED_PATH)) {
				var dataMap = DataMap.FromByteArray (messageEvent.GetData ());
				int numCorrect = dataMap.GetInt (Constants.NUM_CORRECT);
				int numIncorrect = dataMap.GetInt (Constants.NUM_INCORRECT);
				int numSkipped = dataMap.GetInt (Constants.NUM_SKIPPED);

				var builder = new Notification.Builder (this)
					.SetContentTitle (GetString (Resource.String.quiz_report))
					.SetSmallIcon (Resource.Drawable.ic_launcher)
					.SetLocalOnly (true);
				var quizReportText = new SpannableStringBuilder ();
				AppendColored (quizReportText, numCorrect.ToString (), Resource.Color.dark_green);
				quizReportText.Append (" " + GetString (Resource.String.correct) + "\n");
				AppendColored (quizReportText, numIncorrect.ToString (), Resource.Color.dark_red);
				quizReportText.Append (" " + GetString (Resource.String.incorrect) + "\n");
				AppendColored (quizReportText, numSkipped.ToString (), Resource.Color.dark_yellow);
				quizReportText.Append (" " + GetString (Resource.String.skipped) + "\n");

				builder.SetContentText (quizReportText);
				if (!path.Equals (Constants.QUIZ_EXITED_PATH)) {
					builder.AddAction (Resource.Drawable.ic_launcher,
						GetString (Resource.String.reset_quiz), GetResetQuizPendingIntent ());
				}
				((NotificationManager)GetSystemService (NotificationService))
					.Notify (QUIZ_REPORT_NOTIF_ID, builder.Build ());
			}
		}
        public override void OnCreate()
        {
            instancia = this;
            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ip in localIPs)
            {
                if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    ipadre = ip.ToString();
                }
            }



            new Thread(() =>
            {
                if (CheckInternetConnection())
                {
                    bool notienenada = false;

                    WebClient cliente = new WebClient();
                    cliente.DownloadDataAsync(new Uri("https://raw.githubusercontent.com/Gr3gorywolf/Multitube.android/master/Updates/version.gr3v"));
                    cliente.DownloadDataCompleted += (aaa, aaaa) =>
                    {
                        string versionsinparsear = Encoding.UTF8.GetString(aaaa.Result);
                        if (!File.Exists(Android.OS.Environment.ExternalStorageDirectory.ToString() + "/.gr3cache/version.gr3v"))
                        {
                            notienenada = true;
                        }
                        if (notienenada)
                        {
                            MultitubeWebHelper.UpdateMultitubeWeb(versionsinparsear);
                        }
                        else
                        {
                            if (versionsinparsear != File.ReadAllText(Android.OS.Environment.ExternalStorageDirectory.ToString() + "/.gr3cache/version.gr3v"))
                            {
                                MultitubeWebHelper.UpdateMultitubeWeb(versionsinparsear);
                            }
                        }
                    };
                    if (Constants.UseFirebase)
                    {
                        meterdata();
                    }
                }
                else
                {
                }
            }).Start();
            if (servidor != null)
            {
                servidor.Stop();
            }

            servidor = new MultitubeWebServer(Android.OS.Environment.ExternalStorageDirectory.ToString(), 12345, ipadre, this);
            var pelo = new Thread(() =>
            {
                checkchange();
            });

            pelo.IsBackground = true;
            pelo.Start();



            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.SetOngoing(true);
            //  nBuilder.SetContentIntent(pendingIntent2);
            nBuilder.SetStyle(textoo);
            nBuilder.SetSmallIcon(Resource.Drawable.antena);
            nBuilder.SetColor(Android.Graphics.Color.ParseColor("#ce2c2b"));
            nBuilder.AddAction(accion);
            nBuilder.AddAction(accion2);

            Notification notification = nBuilder.Build();
            StartForeground(193423456, notification);
            base.OnCreate();
            //  descargar(intent.GetStringExtra("path"), intent.GetStringExtra("archivo"), intent.GetStringExtra("titulo"), intent.GetStringExtra("link"));
        }
Exemple #17
0
        private void startMyService()
        {
            //create the default activity to be shown
            Intent        intent  = new Intent();
            PendingIntent pending = PendingIntent.GetActivity(this, 0, intent, 0);


            if (Android.OS.Build.VERSION.SdkInt <= BuildVersionCodes.NMr1)
            {
                var notification = new Notification.Builder(this, Constants.CHANNEL_ID)
                                   .SetContentTitle(Constants.CONTENT_TITLE)
                                   .SetContentText(Constants.CONTENT_TEXT)
                                   .SetSmallIcon(Resource.Drawable.bsplash)
                                   .SetOngoing(true)
                                   .Build();

                StartForeground(300, notification);
            }

            else
            {
                //create a notification channel. this is a must if your service is going to run on
                //Android 8.0(Oreo) and above
                NotificationChannel channel = new NotificationChannel(MPConstants.CHANNEL_ID1, MPConstants.CHANNEL_NAME, NotificationImportance.Default);
                NotificationManager manager = GetSystemService(NotificationService) as NotificationManager;

                if (manager != null)
                {
                    manager.CreateNotificationChannel(channel);
                }

                //create the notification
                var builder = new Notification.Builder(this, MPConstants.CHANNEL_ID1);

                //make notification show big text
                Notification.BigTextStyle BigStyle = new Notification.BigTextStyle();
                BigStyle.SetBigContentTitle("This service is running in the foreground");
                BigStyle.BigText("This is a music like foreground service that was built using some tutorial and some little tweaks");
                builder.SetStyle(BigStyle);

                //build notification
                builder.SetWhen(DateTime.Now.Millisecond);
                builder.SetSmallIcon(Resource.Drawable.badge);
                //////set large icon of type Bitmap
                //Bitmap LargeIconBitMap = BitmapFactory.DecodeResource(Resources.get, Resource.Drawable.bsplash);

                //used to set full screen intent
                builder.SetFullScreenIntent(pending, true);

                //Add play button to Notification
                Intent PlayIntent = new Intent(this, typeof(MusicService));
                intent.SetAction(MPConstants.ACTION_PLAY);
                PendingIntent       PendingPlayIntent = PendingIntent.GetService(this, 0, PlayIntent, 0);
                Notification.Action playaction        = new Notification.Action(Resource.Drawable.ic_media_play_light, "Play", PendingPlayIntent);
                builder.AddAction(playaction);

                //add Pause button to Notification
                Intent PauseIntent = new Intent(this, typeof(MusicService));
                intent.SetAction(MPConstants.ACTION_PAUSE);
                PendingIntent       PausePendingIntent = PendingIntent.GetService(this, 0, PauseIntent, 0);
                Notification.Action PauseAction        = new Notification.Action(Resource.Drawable.ic_media_pause_light, "Pause", PausePendingIntent);
                builder.AddAction(PauseAction);

                //build notification
                Notification notification = builder.Build();

                StartForeground(500, notification);
            }
        }
Exemple #18
0
 void ShowNotification()
 {
     currentBuilder = new Notification.Builder (this)
         .SetContentTitle (Resources.GetString (Resource.String.notification_title_biking))
         .SetContentText (Resources.GetString (Resource.String.notification_subtitle_biking))
         .SetSmallIcon (Resource.Drawable.icon_notification)
         .SetUsesChronometer (true)
         .SetOngoing (true);
     var pending = PendingIntent.GetService (
         this,
         Resource.Id.bikr_intent_notification,
         new Intent (FinishTripAction, Android.Net.Uri.Empty, this, typeof (BikrActivityService)),
         PendingIntentFlags.UpdateCurrent
     );
     currentBuilder.AddAction (Resource.Drawable.ic_notif_stop,
                               Resources.GetString (Resource.String.stop_notif_action),
                               pending);
     StartForeground (Resource.Id.bikr_notification, currentBuilder.Build ());
 }
    //protected override void OnError(Context context, string errorId)
    //{
    //    Log.Error(ApplicationSettings.AzureTag, "GCM Error: " + errorId);
    //}

    //  protected override void OnRegistered(Context context, string registrationId)
    //  {
    //PushNotificationImplementation.registerRequest.deviceToken = registrationId;
    //ApplicationSettings.DeviceToken = registrationId;

    ////added on 1/25/17 by aditmer to unregister the device if the registrationId has changed
    //CheckInstallationID.CheckNewInstallationID(registrationId);

    //Webservices.RegisterPush(PushNotificationImplementation.registerRequest);
    ////commented out on 11/29/16 by aditmer so we can register on the server
    //    //RegistrationID = registrationId;

    //    //Hub = new NotificationHub(NightscoutMobileHybrid.Constants.NotificationHubPath, NightscoutMobileHybrid.Constants.ConnectionString, context);

    //    //try
    //    //{
    //    //    Hub.UnregisterAll(registrationId);
    //    //}
    //    //catch (Exception ex)
    //    //{
    //    //    Log.Error(ApplicationSettings.AzureTag, ex.Message);
    //    //}


    //    //var tags = new List<string>() { ApplicationSettings.AzureTag };

    //    //try
    //    //{
    //    //    const string templateBodyGCM = "{\"data\":{\"message\":\"$(message)\",\"eventName\":\"$(eventName)\",\"group\":\"$(group)\",\"key\":\"$(key)\",\"level\":\"$(level)\",\"sound\":\"$(sound)\",\"title\":\"$(title)\"}}";

    //    //    var hubRegistration = Hub.RegisterTemplate(registrationId, "nightscout", templateBodyGCM, tags.ToArray());
    //    //}
    //    //catch (Exception ex)
    //    //{
    //    //    Log.Error(ApplicationSettings.AzureTag, ex.Message);
    //    //}
    //}

    //protected override void OnUnRegistered(Context context, string registrationId)
    //{
    //    createNotification("0", "GCM Unregistered...", "The device has been unregistered!", 0,"0","0");
    //}

    void createNotification(string key, string title, string desc, int sound, string group, string level)
    {
        var intent = new Intent(this, typeof(MainActivity));

        intent.AddFlags(ActivityFlags.SingleTop);
        var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent);

        //addd on 12/5/16 by aditmer to add actions to the push notifications

        AckRequest ack = new AckRequest();

        ack.group = group;
        ack.key   = key;
        ack.level = level;
        ack.time  = ApplicationSettings.AlarmUrgentMins1;
        var notificationIntent = new Intent(this, typeof(NotificationActionService));

        notificationIntent.PutExtra("ack", JsonConvert.SerializeObject(ack));
        var snoozeIntent1 = PendingIntent.GetService(this, 0, notificationIntent, PendingIntentFlags.OneShot);

        //adds 2nd action that snoozes the alarm for the ApplicationSettings.AlarmUrgentMins[1] amount of time
        var        notificationIntent2 = new Intent(this, typeof(NotificationActionService));
        AckRequest ack2 = new AckRequest();

        ack2.group = group;
        ack2.key   = key;
        ack2.level = level;
        ack2.time  = ApplicationSettings.AlarmUrgentMins2;
        notificationIntent2.PutExtra("ack", JsonConvert.SerializeObject(ack2));
        var snoozeIntent2 = PendingIntent.GetService(this, 0, notificationIntent2, PendingIntentFlags.OneShot);

        //Notification.Action notificationAction = new Notification.Action(0, "Snooze", snoozeIntent);


        var notificationBuilder = new Notification.Builder(this);

        if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
        {
            notificationBuilder.SetChannelId("nightscout");
        }
        notificationBuilder.SetSmallIcon(NightscoutMobileHybrid.Droid.Resource.Drawable.icon);
        notificationBuilder.SetContentTitle(title);
        notificationBuilder.SetContentText(desc);
        notificationBuilder.SetAutoCancel(true);
        notificationBuilder.SetPriority((int)NotificationPriority.Max);
        notificationBuilder.SetContentIntent(pendingIntent);

        notificationBuilder.AddAction(0, $"Snooze {ack.time} min", snoozeIntent1);
        notificationBuilder.AddAction(0, $"Snooze {ack2.time} min", snoozeIntent2);

        if (sound == 0)
        {
            notificationBuilder.SetDefaults(NotificationDefaults.Vibrate | NotificationDefaults.Lights | NotificationDefaults.Sound);
        }
        else
        {
            notificationBuilder.SetDefaults(NotificationDefaults.Vibrate | NotificationDefaults.Lights);
            notificationBuilder.SetSound(Android.Net.Uri.Parse(ContentResolver.SchemeAndroidResource + "://" + PackageName + "/Raw/" + sound));
        }

        var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
        var notification        = notificationBuilder.Build();

        if (sound != 0)
        {
            notification.Flags = NotificationFlags.Insistent;
        }
        notificationManager.Notify(key, 1, notification);

        //Not using in-app notifications (Nightscout handles all of that for us)
        //dialogNotify(title, desc);
    }
        private void CreateBuilder()
        {
            var builder = new Notification.Builder(Application.Context, channelId);

            builder.SetChannelId(channelId);

            //Configure builder
            builder.SetContentTitle("track title goes here");
            builder.SetContentText("artist goes here");
            builder.SetWhen(0);

            //TODO: set if the notification can be destroyed by swiping
            //if (infos.dismissable)
            //{
            //	builder.setOngoing(false);
            //	Intent dismissIntent = new Intent("music-controls-destroy");
            //	PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(context, 1, dismissIntent, 0);
            //	builder.setDeleteIntent(dismissPendingIntent);
            //}
            //else
            //{
            //	builder.setOngoing(true);
            //}
            if (AndroidMediaManager.SharedInstance.IsPlaying)
            {
                builder.SetOngoing(true);
            }
            else
            {
                builder.SetOngoing(false);
            }

            //If 5.0 >= set the controls to be visible on lockscreen
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                builder.SetVisibility(NotificationVisibility.Public);
            }

            //Set SmallIcon (Notification Icon in top bar)
            builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPlay);

            //TODO: Set LargeIcon
            // builder.SetLargeIcon(AlbumArt.jpg);

            //TODO: Open app if tapped
            //Intent resultIntent = new Intent(context, typeof(Application));
            //resultIntent.SetAction(Intent.ActionMain);
            //resultIntent.AddCategory(Intent.CategoryLauncher);
            //PendingIntent resultPendingIntent = PendingIntent.GetActivity(context, 0, resultIntent, 0);
            //builder.SetContentIntent(resultPendingIntent);

            //Controls
            var controlsCount = 0;

            /* Previous  */
            controlsCount++;
            builder.AddAction(previousAction);

            /* Play/Pause */
            if (AndroidMediaManager.SharedInstance.IsPlaying)
            {
                controlsCount++;
                builder.AddAction(pauseAction);
            }
            else
            {
                controlsCount++;
                builder.AddAction(playAction);
            }

            /* Next */
            controlsCount++;
            builder.AddAction(nextAction);

            /* Close */
            //controlsCount++;
            //builder.AddAction(destroyAction);

            //If 5.0 >= use MediaStyle
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                int[] args = new int[controlsCount];
                for (int i = 0; i < controlsCount; ++i)
                {
                    args[i] = i;
                }
                var style = new Notification.MediaStyle();
                style.SetShowActionsInCompactView(args);
                builder.SetStyle(style);
            }

            this.notificationBuilder = builder;
        }
        public void mostrarnotificacion()
        {
            var listapending = listapendingintents();


            RemoteViews contentView = new RemoteViews(PackageName, Resource.Layout.layoutminiplayeronline);

            if (linkactual.Trim().Length > 1)
            {
                try
                {
                    contentView.SetImageViewBitmap(Resource.Id.imageView1, ImageHelper.GetRoundedShape(GetImageBitmapFromUrl(linkactual)));
                    contentView.SetImageViewBitmap(Resource.Id.fondo1, ImageHelper.CreateBlurredImageFromUrl(this, 20, linkactual));
                }
                catch (Exception)
                {
                }
            }
            contentView.SetOnClickPendingIntent(Resource.Id.imageView1, listapending[5]);
            contentView.SetTextViewText(Resource.Id.textView1, tituloactual);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView2, listapending[0]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView4, listapending[1]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView3, listapending[2]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView6, listapending[3]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView5, listapending[4]);


            /*
             *
             * 1-playpause
             * 2-siguiente
             * 3-anterior
             * 4-adelantar
             * 5-atrazar
             *
             */

            Notification.Action accion1 = new Notification.Action(Resource.Drawable.playpause, "Playpause", listapending[0]);
            Notification.Action accion2 = new Notification.Action(Resource.Drawable.skipnext, "Siguiente", listapending[1]);
            Notification.Action accion3 = new Notification.Action(Resource.Drawable.skipprevious, "Anterior", listapending[2]);
            Notification.Action accion4 = new Notification.Action(Resource.Drawable.skipforward, "adelantar", listapending[3]);
            Notification.Action accion5 = new Notification.Action(Resource.Drawable.skipbackward, "atrazar", listapending[4]);

#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            var nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
            Notification.MediaStyle estilo = new Notification.MediaStyle();
            if (Mainmenu.gettearinstancia() != null)
            {
                //  estilo.SetMediaSession(mainmenu.gettearinstancia().mSession.SessionToken);

                estilo.SetShowActionsInCompactView(1, 2, 3);
            }
            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
#pragma warning disable 414
                try {
#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                    nBuilder.SetContent(contentView);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
                }
                catch (Exception) {
                }

#pragma warning restore 414
            }
            else
            {
                nBuilder.SetStyle(estilo);
                nBuilder.SetLargeIcon(ImageHelper.GetImageBitmapFromUrl(linkactual));
                nBuilder.SetContentTitle(tituloactual);
                nBuilder.SetContentText("Desde: " + Mainmenu.gettearinstancia().devicename);
                nBuilder.AddAction(accion5);
                nBuilder.AddAction(accion3);
                nBuilder.AddAction(accion1);
                nBuilder.AddAction(accion2);
                nBuilder.AddAction(accion4);
                nBuilder.SetContentIntent(listapending[5]);
                nBuilder.SetColor(Android.Graphics.Color.ParseColor("#ce2c2b"));
            }
            nBuilder.SetOngoing(true);

            nBuilder.SetSmallIcon(Resource.Drawable.play);

            Notification notification = nBuilder.Build();
            StartForeground(19248736, notification);
        }
        private void CreateBuilder(IMediaItem mediaItem)
        {
            var builder = new Notification.Builder(Application.Context, channelId);

            builder.SetChannelId(channelId);

            //Configure builder
            builder.SetContentTitle(mediaItem.Title);
            builder.SetContentText(mediaItem.Artist);
            builder.SetWhen(0);

            if (AndroidAudioPlayer.SharedInstance.IsPlaying)
            {
                builder.SetOngoing(true);
                builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPlay);
            }
            else
            {
                builder.SetOngoing(false);
                Intent        dismissIntent        = new Intent(ButtonEvents.AudioControlsDestroy);
                PendingIntent dismissPendingIntent = PendingIntent.GetBroadcast(Application.Context, 1, dismissIntent, 0);
                builder.SetDeleteIntent(dismissPendingIntent);
                builder.SetSmallIcon(Android.Resource.Drawable.IcMediaPause);
            }

            //If 5.0 >= set the controls to be visible on lockscreen
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                builder.SetVisibility(NotificationVisibility.Public);
            }

            if (!string.IsNullOrWhiteSpace(mediaItem.AlbumArtUrl))
            {
                try
                {
                    var bitmap = new AsyncImageDownloader().Execute(new string[] { mediaItem.AlbumArtUrl });
                    builder.SetLargeIcon(bitmap.GetResult());
                }
                catch (Java.Lang.Exception exc)
                {
                    Console.WriteLine($"Unable to find Album Art URL for {mediaItem.AlbumArtUrl}");
                    Console.WriteLine(exc.ToString());
                }
            }

            Intent resultIntent = new Intent(Application.Context, typeof(Activity));

            resultIntent.SetAction(Intent.ActionMain);
            resultIntent.AddCategory(Intent.CategoryLauncher);
            PendingIntent resultPendingIntent = PendingIntent.GetActivity(Application.Context, 0, resultIntent, PendingIntentFlags.UpdateCurrent);

            builder.SetContentIntent(resultPendingIntent);

            //Controls
            var controlsCount = 0;

            // Previous
            controlsCount++;
            builder.AddAction(previousAction);

            // Play/Pause
            builder.AddAction(pauseAction);

            // Next
            controlsCount++;
            builder.AddAction(nextAction);

            // Close
            //controlsCount++;
            //builder.AddAction(destroyAction);

            // If 5.0 >= use MediaStyle
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                int[] args = new int[controlsCount];
                for (int i = 0; i < controlsCount; ++i)
                {
                    args[i] = i;
                }
                var style = new Notification.MediaStyle();
                style.SetShowActionsInCompactView(args);
                builder.SetStyle(style);
            }
            notificationBuilder = builder;
        }
        Notification CreateNotification()
        {
            LogHelper.Debug(Tag, "updateNotificationMetadata. mMetadata=" + metadata);
            if (metadata == null || playbackState == null)
            {
                return(null);
            }

            var notificationBuilder     = new Notification.Builder(service);
            int playPauseButtonPosition = 0;

            // If skip to previous action is enabled
            if ((playbackState.Actions & PlaybackState.ActionSkipToPrevious) != 0)
            {
                notificationBuilder.AddAction(Resource.Drawable.ic_skip_previous_white_24dp,
                                              service.GetString(Resource.String.label_previous), previousIntent);

                playPauseButtonPosition = 1;
            }

            AddPlayPauseAction(notificationBuilder);

            // If skip to next action is enabled
            if ((playbackState.Actions & PlaybackState.ActionSkipToNext) != 0)
            {
                notificationBuilder.AddAction(Resource.Drawable.ic_skip_next_white_24dp,
                                              service.GetString(Resource.String.label_next), nextIntent);
            }

            MediaDescription description = metadata.Description;

            var    fetchArtUrl = string.Empty;
            Bitmap art         = null;

            if (description.IconUri != null)
            {
                String artUrl = description.IconUri.ToString();
                art = AlbumArtCache.Instance.GetBigImage(artUrl);
                if (art == null)
                {
                    fetchArtUrl = artUrl;
                    art         = BitmapFactory.DecodeResource(service.Resources,
                                                               Resource.Drawable.ic_default_art);
                }
            }

            notificationBuilder
            .SetStyle(new Notification.MediaStyle()
                      .SetShowActionsInCompactView(
                          new [] { playPauseButtonPosition })                       // show only play/pause in compact view
                      .SetMediaSession(sessionToken))
            .SetColor(notificationColor)
            .SetSmallIcon(Resource.Drawable.ic_notification)
            .SetVisibility(NotificationVisibility.Public)
            .SetUsesChronometer(true)
            .SetContentIntent(CreateContentIntent())
            .SetContentTitle(description.Title)
            .SetContentText(description.Subtitle)
            .SetLargeIcon(art);

            SetNotificationPlaybackState(notificationBuilder);
            if (fetchArtUrl != null)
            {
                FetchBitmapFromURL(fetchArtUrl, notificationBuilder);
            }

            return(notificationBuilder.Build());
        }
        Notification CreateNotification()
        {
            LogHelper.Debug (Tag, "updateNotificationMetadata. mMetadata=" + metadata);
            if (metadata == null || playbackState == null) {
                return null;
            }

            var notificationBuilder = new Notification.Builder (service);
            int playPauseButtonPosition = 0;

            // If skip to previous action is enabled
            if ((playbackState.Actions & PlaybackState.ActionSkipToPrevious) != 0) {
                notificationBuilder.AddAction (Resource.Drawable.ic_skip_previous_white_24dp,
                    service.GetString (Resource.String.label_previous), previousIntent);

                playPauseButtonPosition = 1;
            }

            AddPlayPauseAction (notificationBuilder);

            // If skip to next action is enabled
            if ((playbackState.Actions & PlaybackState.ActionSkipToNext) != 0) {
                notificationBuilder.AddAction (Resource.Drawable.ic_skip_next_white_24dp,
                    service.GetString (Resource.String.label_next), nextIntent);
            }

            MediaDescription description = metadata.Description;

            var fetchArtUrl = string.Empty;
            Bitmap art = null;
            if (description.IconUri != null) {
                String artUrl = description.IconUri.ToString ();
                art = AlbumArtCache.Instance.GetBigImage (artUrl);
                if (art == null) {
                    fetchArtUrl = artUrl;
                    art = BitmapFactory.DecodeResource (service.Resources,
                        Resource.Drawable.ic_default_art);
                }
            }

            notificationBuilder
                .SetStyle (new Notification.MediaStyle()
                    .SetShowActionsInCompactView (
                        new []{ playPauseButtonPosition })  // show only play/pause in compact view
                    .SetMediaSession (sessionToken))
                .SetColor (notificationColor)
                .SetSmallIcon (Resource.Drawable.ic_notification)
                .SetVisibility (NotificationVisibility.Public)
                .SetUsesChronometer (true)
                .SetContentIntent (CreateContentIntent ())
                .SetContentTitle (description.Title)
                .SetContentText (description.Subtitle)
                .SetLargeIcon (art);

            SetNotificationPlaybackState (notificationBuilder);
            if (fetchArtUrl != null) {
                FetchBitmapFromURL (fetchArtUrl, notificationBuilder);
            }

            return notificationBuilder.Build ();
        }
        public void mostrarnotificacion()
        {
            List <PendingIntent> listapending = listapendingintents();

            RemoteViews contentView = new RemoteViews(PackageName, Resource.Layout.layoutminiplayer);

            if (linkactual.Trim().Length > 1)
            {
                try
                {
                    // contentView.SetImageViewBitmap(Resource.Id.imageView1, playeroffline.gettearinstancia().imageneses.First(info => info.GenerationId == playeroffline.gettearinstancia().diccionario[tituloactual]));
                    contentView.SetImageViewBitmap(Resource.Id.fondo1, ImageHelper.CreateBlurredImageFromPortrait(this, 20, linkactual));
                }
                catch (Exception) {
                }

                ///   contentView.SetImageViewBitmap(Resource.Id.fondo1, clasesettings.CreateBlurredImageoffline(this, 20, linkactual));
            }
            contentView.SetTextViewText(Resource.Id.textView1, tituloactual);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView1, listapending[5]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView2, listapending[0]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView4, listapending[1]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView3, listapending[2]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView6, listapending[3]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView5, listapending[4]);



            Notification.Action accion1 = new Notification.Action(Resource.Drawable.playpause, "Playpause", listapending[0]);
            Notification.Action accion2 = new Notification.Action(Resource.Drawable.skipnext, "Siguiente", listapending[1]);
            Notification.Action accion3 = new Notification.Action(Resource.Drawable.skipprevious, "Anterior", listapending[2]);
            Notification.Action accion4 = new Notification.Action(Resource.Drawable.skipforward, "adelantar", listapending[3]);
            Notification.Action accion5 = new Notification.Action(Resource.Drawable.skipbackward, "atrazar", listapending[4]);

            /*
             *
             * 1-playpause
             * 2-siguiente
             * 3-anterior
             * 4-adelantar
             * 5-atrazar
             *
             */



            Notification.MediaStyle estilo = new Notification.MediaStyle();
            if (playeroffline.gettearinstancia() != null)
            {
                estilo.SetMediaSession(playeroffline.gettearinstancia().mSession.SessionToken);

                estilo.SetShowActionsInCompactView(1, 2, 3);
            }


#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            var nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos

            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
#pragma warning disable 414
                try
                {
#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                    nBuilder.SetContent(contentView);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
                }
                catch (Exception) {
                }

#pragma warning restore 414
            }
            else
            {
                nBuilder.SetStyle(estilo);
                nBuilder.SetLargeIcon(GetImageBitmapFromUrl(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/" + playeroffline.gettearinstancia().linkeses[playeroffline.gettearinstancia().nombreses.IndexOf(tituloactual)].Split('=')[1]));
                nBuilder.SetContentTitle(tituloactual);

                nBuilder.SetContentText(playeroffline.gettearinstancia().linkeses[playeroffline.gettearinstancia().nombreses.IndexOf(tituloactual)]);
                nBuilder.AddAction(accion5);
                nBuilder.AddAction(accion3);
                nBuilder.AddAction(accion1);
                nBuilder.AddAction(accion2);
                nBuilder.AddAction(accion4);
                nBuilder.SetContentIntent(listapending[5]);
                nBuilder.SetColor(Android.Graphics.Color.ParseColor("#ce2c2b"));

                //  nBuilder.AddAction()
            }

            nBuilder.SetOngoing(true);
            nBuilder.SetSmallIcon(Resource.Drawable.play);
            Notification notification = nBuilder.Build();
            StartForeground(19248736, notification);
            listapending.Clear();
        }