Beispiel #1
0
        public static void BuildNotification(String songId)
        {
            MediaMetadataRetriever metadata = SongMetadata.GetMetadata(songId);

            string title   = metadata.ExtractMetadata(MetadataKey.Title);
            string content = metadata.ExtractMetadata(MetadataKey.Artist);

            if (title == null || content == null)
            {
                title   = "TubeLoad";
                content = AndroidSongsManager.Instance.GetSong(songId).Name.Replace(".mp3", "");
            }

            builder.SetSmallIcon(Resource.Drawable.icon);
            Drawable drawable = SongMetadata.GetSongPicture(songId);
            Bitmap   bitmap;

            if (drawable != null)
            {
                bitmap = ((BitmapDrawable)SongMetadata.GetSongPicture(songId)).Bitmap;
            }
            else
            {
                bitmap = BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Drawable.default_song_image);
            }

            if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.M)
            {
                RemoteViews notificationLayoutExpanded = new RemoteViews(Application.Context.PackageName, Resource.Layout.view_notification_actions);
                notificationLayoutExpanded.SetTextViewText(Resource.Id.notificationTitle, title);
                notificationLayoutExpanded.SetTextViewText(Resource.Id.notificationContent, content);
                notificationLayoutExpanded.SetImageViewBitmap(Resource.Id.songImg, bitmap);
                CreateNotificationMediaActions(notificationLayoutExpanded);
                builder.SetCustomBigContentView(notificationLayoutExpanded);
                builder.SetContentTitle(title);
            }
            else
            {
                builder.SetLargeIcon(bitmap);
                builder.SetContentTitle(title);
                builder.SetContentText(content);
            }

            songNotification = builder.Build();

            notificationManager.Notify(SONG_NOTIFICATION_ID, songNotification);
        }