David Barishev David Barishev - 1 month ago 19
Android Question

Creating custom notification with xamarin.android

I have been trying to make a fully custom notification with Xamarin.android.

My project targets min API of 14, so expended notification are supported. I'm trying to achieve the same look for all API's so i'm using

Android.Support.V4.App.NotificationCompat.Builder
.

I have found out that you can use setCustomContentView to set a custom View that will change the layout of the notification complitly, which is what i aim for.

Here is the code that i have tried to run:

RemoteViews widgetLayout = new RemoteViews(PackageName,Resource.Layout.SingleNotificationLayout);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.SetCustomBigContentView(widgetLayout);

notificationManager.Notify(notificationId, builder.Build());


Which
Resource.Layout.SingleNotificationLayout
is a layout file for the notification.Im running this code from
MainActiviy
.Code is modified from here.

The error that i'm facing is that
SetCustomBigContentView
is not found, specifically :

'NotificationCompat.Builder' does not contain a definition for 'SetCustomBigContentView' and no extension method 'SetCustomBigContentView' accepting a first argument of type 'NotificationCompat.Builder' could be found (are you missing a using directive or an assembly reference?)


Here are my installed packages:

<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Design" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v14.Preference" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v4" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.GridLayout" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.Preference" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.RecyclerView" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="23.4.0.1" targetFramework="monoandroid70" />


What am i missing ? Is the equivalent function named differently ?

Answer

You will need to use the latest pre-release packages for the support libraries. Specifically https://www.nuget.org/packages/Xamarin.Android.Support.v4/24.2.1-rc1 which includes a new assembly: Xamarin.Android.Support.Compat. This will include the method you're looking for:

EX: Looking through Xamarin.Android.Support.Compat in DotPeek

enter image description here

However it's not included in the current stable(23.4.0.1) as you can see here:

EX: Looking through Xamarin.Android.Support.v4 in DotPeek

enter image description here