question

Brickman7713-3172 avatar image
0 Votes"
Brickman7713-3172 asked tariqalzubi-4374 answered

Xamarin Media Manager Notification Controls

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


dotnet-xamarin
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Brickman7713-3172 , have you upload all the files of your app. When I built your application, some errors appeared, the message showed that certain files cannot be found.

0 Votes 0 ·

Hello, what are some of the files not found?

0 Votes 0 ·

Try this, I zipped the folder on my computer and there are no files outside of it as far as I know.


TheLight_3.11.2021.zip


0 Votes 0 ·
Show more comments
JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered JessieZhang-2116 commented

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.



· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, thanks for the reply. Where would this code go, and does it require any "using" statements? Sorry I am very new to this.

0 Votes 0 ·

This is my custom local notification code snippet. It just use the V4 library.

My using is:

 using System;
 using Android.App;
 using Android.Content;
 using Android.Graphics;
 using Android.Media;
 using Android.OS;
 using Android.Support.V4.App;
 using Android.Support.V7.App;
 using Android.Widget;
    
 using Java.Lang;
    
 using TaskStackBuilder = Android.Support.V4.App.TaskStackBuilder;
 using NotificationCompact = Android.Support.V4.App.NotificationCompat;


0 Votes 0 ·

Ok thanks, what file would the code go in though, MainActivity.cs?

0 Votes 0 ·
Show more comments
tariqalzubi-4374 avatar image
0 Votes"
tariqalzubi-4374 answered

@Brickman7713-3172
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 ...

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.