コード例 #1
0
        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());
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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, ImageHelper.GetRoundedShape(GetImageBitmapFromUrl("https://i.ytimg.com/vi/" + linkactual.Split('=')[1] + "/mqdefault.jpg")));
                    contentView.SetImageViewBitmap(Resource.Id.fondo1, ImageHelper.CreateBlurredImageFromUrl(this, 20, linkactual));
                }
                catch (Exception)
                {
                }
            }
            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]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView1, listapending[5]);

            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]);

            Notification.MediaStyle estilo = new Notification.MediaStyle();
            if (YoutubePlayerServerActivity.gettearinstancia() != null)
            {
                estilo.SetMediaSession(YoutubePlayerServerActivity.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)
            {
                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) {
                }
            }
            else
            {
                nBuilder.SetStyle(estilo);
                nBuilder.SetLargeIcon(ImageHelper.GetImageBitmapFromUrl("http://i.ytimg.com/vi/" + linkactual.Split('=')[1] + "/mqdefault.jpg"));
                nBuilder.SetContentTitle(tituloactual);
                nBuilder.SetContentText(linkactual);
                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);
            listapending.Clear();
        }