Android notifications using MAUI (Part 4 of 10)

Extending on what we did in “Android notifications using MAUI (Part 3 of 10)” we’re going to look an nig text style and inbox style as per Notifications Tutorial Part 4 – BIG PICTURE STYLE + MEDIA STYLE – Android Studio Tutorial.

Overview

This is not a very useful post as I again found that either I’m missing something or there’s issues in MAUI, for the sake of argument I’ll assume it’s my fault. Anyway I’m still going to show how (I think) you can display a larger bitmap as well as apply the MediaStyle which has the ability to handle up to five actions
(obviously useful for play, pause, back, forward etc.) as well as three actions in a collapsed state.

In the SendOnChannel1 method from our previous posts, we’ll add a BigPictureStyle to our NotificationCompat.Builder like this, to begin with I’ve just renamed the variable as per the tutorial video

var picture = BitmapFactory.DecodeResource(Android.App.Application.Context.Resources, Resource.Drawable.AppIcon);

Now we add the style like this

.SetStyle(new NotificationCompat
  .BigPictureStyle()
  .BigPicture(picture)
  .BigLargeIcon(null))

Note: Again I’m having trouble with the bitmap side of things, i.e. not displaying on the emulator. I will update here if I find it’s something I’ve done incorrectly. What you will see is a larger notification when you expand the notifications via the status bar, presumably to accommodate my picture

Let’s now create a pretend media play or at least the actions for one on channel 2 notifications. As such I added PNG’s to Platforms/Android/Resources/drawable for like, dislike, next, pause, previous actions.

We need to update our SendOnChannel2 method to add the following actions

.AddAction(Resource.Drawable.dislike, "Dislike", null)
.AddAction(Resource.Drawable.previous, "Previous", null)
.AddAction(Resource.Drawable.pause, "Pause", null)
.AddAction(Resource.Drawable.next, "Next", null)
.AddAction(Resource.Drawable.like, "Like", null)

Nothing too much different there apart from I’m not bothering to set intents for the actions (i.e. they do nothing). Now we need to set the style to MediaStyle and here we supply three indexes (zero-based) into our actions to denote the actions available when the notification is not expanded.

.SetStyle(new AndroidX.Media.App.NotificationCompat.MediaStyle()
  // the id's for the actions listed as actions
  .SetShowActionsInCompactView(1, 2, 3) 
  /*.SetMediaSession(_mediaSession.SessionToken)*/) 

As you can I’ve commented out the SetMediaSession (which is shown in the code listed at the end of this post) – I wasn’t able to get this to work as per the tutorial video, when declaring it in the constructor I was getting a JNI failure – again this might be something I’ve done wrong, so best to take a look at the source code on my repos. and decide what to do with this.

Code

Code for this an subsequent posts is found on my blog project.