Exemplo n.º 1
0
        Notification buildCustomNotification(ServiceActions action)
        {
            PendingIntent pi    = PendingIntent.GetActivity(ApplicationContext, 0, new Intent(ApplicationContext, typeof(MainActivity)), PendingIntentFlags.CancelCurrent);
            PendingIntent play  = PendingIntent.GetService(ApplicationContext, 1, new Intent(ActionPlay), PendingIntentFlags.CancelCurrent);
            PendingIntent pause = PendingIntent.GetService(ApplicationContext, 2, new Intent(ActionPause), PendingIntentFlags.CancelCurrent);

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

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

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

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

            return(builder.Notification);
        }
Exemplo n.º 2
0
        void ShowNotification(bool custom)
        {
            Resources           res = Resources;
            NotificationManager notificationManager = (NotificationManager)GetSystemService(
                NotificationService);

            Notification.Builder builder = new Notification.Builder(this)
                                           .SetSmallIcon(Resource.Drawable.ic_stat_notify_example)
                                           .SetAutoCancel(true)
                                           .SetTicker(GetString(Resource.String.notification_text))
                                           .SetContentIntent(GetDialogPendingIntent("Tapped the notification entry."));

            if (custom)
            {
                // Sets a custom content view for the notification, including an image button.
                RemoteViews layout = new RemoteViews(PackageName, Resource.Layout.notification);
                layout.SetTextViewText(Resource.Id.notification_title, GetString(Resource.String.app_name));
                layout.SetOnClickPendingIntent(Resource.Id.notification_button,
                                               GetDialogPendingIntent("Tapped the 'dialog' button in the notification."));
                builder.SetContent(layout);

                // Notifications in Android 3.0 now have a standard mechanism for displaying large
                // bitmaps such as contact avatars. Here, we load an example image and resize it to the
                // appropriate size for large bitmaps in notifications.
                Bitmap largeIconTemp = BitmapFactory.DecodeResource(res,
                                                                    Resource.Drawable.notification_default_largeicon);
                Bitmap largeIcon = Bitmap.CreateScaledBitmap(
                    largeIconTemp,
                    res.GetDimensionPixelSize(Android.Resource.Dimension.NotificationLargeIconWidth),
                    res.GetDimensionPixelSize(Android.Resource.Dimension.NotificationLargeIconHeight),
                    false);
                largeIconTemp.Recycle();

                builder.SetLargeIcon(largeIcon);
            }
            else
            {
                builder
                .SetNumber(7)                  // An example number.
                .SetContentTitle(GetString(Resource.String.app_name))
                .SetContentText(GetString(Resource.String.notification_text));
            }

            notificationManager.Notify(NotificationDefault, builder.Notification);
        }
        void ShowNotification(bool custom)
        {
            Resources res = Resources;
            NotificationManager notificationManager = (NotificationManager) GetSystemService (
                NotificationService);

            Notification.Builder builder = new Notification.Builder (this)
                .SetSmallIcon (Resource.Drawable.ic_stat_notify_example)
                .SetAutoCancel (true)
                .SetTicker (GetString(Resource.String.notification_text))
                .SetContentIntent (GetDialogPendingIntent ("Tapped the notification entry."));

            if (custom) {
                // Sets a custom content view for the notification, including an image button.
                RemoteViews layout = new RemoteViews (PackageName, Resource.Layout.notification);
                layout.SetTextViewText (Resource.Id.notification_title, GetString (Resource.String.app_name));
                layout.SetOnClickPendingIntent (Resource.Id.notification_button,
                    GetDialogPendingIntent ("Tapped the 'dialog' button in the notification."));
                builder.SetContent (layout);

                // Notifications in Android 3.0 now have a standard mechanism for displaying large
                // bitmaps such as contact avatars. Here, we load an example image and resize it to the
                // appropriate size for large bitmaps in notifications.
                Bitmap largeIconTemp = BitmapFactory.DecodeResource (res,
                    Resource.Drawable.notification_default_largeicon);
                Bitmap largeIcon = Bitmap.CreateScaledBitmap (
                    largeIconTemp,
                    res.GetDimensionPixelSize (Android.Resource.Dimension.NotificationLargeIconWidth),
                    res.GetDimensionPixelSize (Android.Resource.Dimension.NotificationLargeIconHeight),
                    false);
                largeIconTemp.Recycle ();

                builder.SetLargeIcon (largeIcon);

            } else {
                builder
                .SetNumber (7) // An example number.
                .SetContentTitle (GetString (Resource.String.app_name))
                .SetContentText (GetString (Resource.String.notification_text));
            }

            notificationManager.Notify (NotificationDefault, builder.Notification);
        }
        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);
        }
        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();
        }