Xamarin Media Manager Notification Controls

Brickman7713 21 Reputation points
2021-03-11T00:41:26.29+00:00

Hello, I am trying to stream audio using MediaManager on Xamarin and the streaming is working, but I can't figure out how to customize the notification area when the audio is playing. The main things that I want to change is the notification area background, remove the "previous/next" controls, and change the text displayed. I think I need to use this for the controls CrossMediaManager.Current.NotificationManager.ShowNavigationControls = false; but it gives me the error "IMediaManager does not contain a definition for 'NotificationManager' and no accessible extension method 'NotificationManager' accepting a first argument of type 'IMediaManager' could be found". Thanks in advance!

My entire Visual Studio project
https://github.com/brickman7713/TheLight.v1

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
{count} votes

2 answers

Sort by: Most helpful
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-04-01T07:04:22.357+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    If you want to custom the Notification UI, you can call the function of NotificationCompat.Builder to achieve it.For example, you can use NotificationCompact.BigPictureStyle to set a big picture notification.

    You can refer to the following code:

            var valuesForActivity = new Bundle();  
            valuesForActivity.PutInt(COUNT_KEY, count3);  
    
            // When the user clicks the notification, SecondActivity will start up.  
            var resultIntent = new Intent(this, typeof(PicNotificationActivity));  
    
            // Pass some values to SecondActivity:  
            resultIntent.PutExtras(valuesForActivity);  
    
    
            // Construct a back stack for cross-task navigation:  
            var stackBuilder = TaskStackBuilder.Create(this);  
            stackBuilder.AddParentStack(Class.FromType(typeof(PicNotificationActivity)));  
            stackBuilder.AddNextIntent(resultIntent);  
    
            // Create the PendingIntent with the back stack:              
            var resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);  
    
            // Build the notification:  
            var builder = new NotificationCompat.Builder(this, CHANNEL_ID)  
                          .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it  
                          .SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent.  
                          .SetContentTitle("Button3 Clicked") // Set the title  
                          .SetSmallIcon(Resource.Drawable.logo) // This is the icon to display  
                          .SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.pic1))  
                          .SetContentText($"The button has been clicked {count3} times."); // the message to display.  
                                                                                           // Instantiate the Big Text style:  
                                                                                           //Notification.BigTextStyle textStyle = new Notification.BigTextStyle();  
            builder.SetVisibility(NotificationCompact.VisibilitySecret);  
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)  
            {  
                builder.SetCategory(NotificationCompact.CategoryCall);  
            }  
            // Instantiate the Image (Big Picture) style:  
            NotificationCompact.BigPictureStyle picStyle = new NotificationCompact.BigPictureStyle();  
    
            // Convert the image to a bitmap before passing it into the style:  
            picStyle.BigPicture(BitmapFactory.DecodeResource(Resources, Resource.Drawable.pic1));  
    
            // Set the summary text that will appear with the image:  
            picStyle.SetSummaryText("The summary text goes here.");  
    
            // Plug this style into the builder:  
            builder.SetStyle(picStyle);  
    
    
            // Finally, publish the notification:  
            var notificationManager = NotificationManagerCompat.From(this);  
            notificationManager.Notify(NOTIFICATION_ID3, builder.Build());  
    
         
    

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. tariqalzubi 1 Reputation point
    2021-07-09T17:59:04.84+00:00

    @Brickman7713
    Yeap u are right , there was a some changes related to current library

    old =>
    CrossMediaManager.Current.NotificationManager.ShowNavigationControls = false;
    current =>
    CrossMediaManager.Current.Notification.ShowNavigationControls = false;

    NotificationManager became Notification ...

    0 comments No comments