{"id":9863,"date":"2023-01-15T12:10:27","date_gmt":"2023-01-15T12:10:27","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=9863"},"modified":"2023-01-15T15:16:14","modified_gmt":"2023-01-15T15:16:14","slug":"android-notifications-using-maui-part-4-of-10","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/android-notifications-using-maui-part-4-of-10\/","title":{"rendered":"Android notifications using MAUI (Part 4 of 10)"},"content":{"rendered":"<p>Extending on what we did in &#8220;Android notifications using MAUI (Part 3 of 10)&#8221; we&#8217;re going to look an nig text style and inbox style as per <a href=\"https:\/\/www.youtube.com\/watch?v=s0Q2QKZ4OP8\" rel=\"noopener\" target=\"_blank\">Notifications Tutorial Part 4 &#8211; BIG PICTURE STYLE + MEDIA STYLE &#8211; Android Studio Tutorial<\/a>.<\/p>\n<p><strong>Overview<\/strong><\/p>\n<p>This is not a very useful post as I again found that either I&#8217;m missing something or there&#8217;s issues in MAUI, for the sake of argument I&#8217;ll assume it&#8217;s my fault. Anyway I&#8217;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<br \/>\n (obviously useful for play, pause, back, forward etc.) as well as three actions in a collapsed state.<\/p>\n<p>In the SendOnChannel1 method from our previous posts, we&#8217;ll add a BigPictureStyle to our <em>NotificationCompat.Builder<\/em> like this, to begin with I&#8217;ve just renamed the variable as per the tutorial video<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nvar picture = BitmapFactory.DecodeResource(Android.App.Application.Context.Resources, Resource.Drawable.AppIcon);\r\n<\/pre>\n<p>Now we add the style like this<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n.SetStyle(new NotificationCompat\r\n  .BigPictureStyle()\r\n  .BigPicture(picture)\r\n  .BigLargeIcon(null))\r\n<\/pre>\n<p><em>Note: Again I&#8217;m having trouble with the bitmap side of things, i.e. not displaying on the emulator. I will update here if I find it&#8217;s something I&#8217;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<\/em><\/p>\n<p>Let&#8217;s now create a pretend media play or at least the actions for one on channel 2 notifications. As such I added PNG&#8217;s to Platforms\/Android\/Resources\/drawable for like, dislike, next, pause, previous actions.<\/p>\n<p>We need to update our SendOnChannel2 method to add the following actions<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n.AddAction(Resource.Drawable.dislike, &quot;Dislike&quot;, null)\r\n.AddAction(Resource.Drawable.previous, &quot;Previous&quot;, null)\r\n.AddAction(Resource.Drawable.pause, &quot;Pause&quot;, null)\r\n.AddAction(Resource.Drawable.next, &quot;Next&quot;, null)\r\n.AddAction(Resource.Drawable.like, &quot;Like&quot;, null)\r\n<\/pre>\n<p>Nothing too much different there apart from I&#8217;m not bothering to set intents for the actions (i.e. they do nothing). Now we need to set the style to <em>MediaStyle<\/em> and here we supply three indexes (zero-based) into our actions to denote the actions available when the notification is not expanded.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n.SetStyle(new AndroidX.Media.App.NotificationCompat.MediaStyle()\r\n  \/\/ the id's for the actions listed as actions\r\n  .SetShowActionsInCompactView(1, 2, 3) \r\n  \/*.SetMediaSession(_mediaSession.SessionToken)*\/) \r\n<\/pre>\n<p>As you can I&#8217;ve commented out the SetMediaSession (which is shown in the code listed at the end of this post) &#8211; I wasn&#8217;t able to get this to work as per the tutorial video, when declaring it in the constructor I was getting a JNI failure &#8211; again this might be something I&#8217;ve done wrong, so best to take a look at the source code on my repos. and decide what to do with this.<\/p>\n<p><strong>Code<\/strong><\/p>\n<p>Code for this an subsequent posts is found on my <a href=\"https:\/\/github.com\/putridparrot\/blog-projects\/tree\/master\/AndroidNotificationInMaui\/Part%204\" rel=\"noopener\" target=\"_blank\">blog project<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Extending on what we did in &#8220;Android notifications using MAUI (Part 3 of 10)&#8221; we&#8217;re going to look an nig text style and inbox style as per Notifications Tutorial Part 4 &#8211; BIG PICTURE STYLE + MEDIA STYLE &#8211; Android Studio Tutorial. Overview This is not a very useful post as I again found that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[120,330],"tags":[],"class_list":["post-9863","post","type-post","status-publish","format-standard","hentry","category-android","category-maui"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=9863"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9863\/revisions"}],"predecessor-version":[{"id":9906,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9863\/revisions\/9906"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=9863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=9863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=9863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}