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());
        }
Example #2
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);
                }
            }
        }
        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;
        }
        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();
        }