question

Arzach-0087 avatar image
0 Votes"
Arzach-0087 asked RobCaplan edited

I can't inherit from NotificationManager

I can't inherit from Android.App.NotificationManager:

  public class myNotificationManager : NotificationManager
     {
         protected myNotificationManager(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
         {
        
         }
     }

I have no C# error, but when I build the project I get this error:

 error: constructor NotificationManager in class NotificationManager cannot be applied to given types;
 public class myNotificationManager
 required: Context,Handler
 found: no arguments
 reason: actual and formal argument lists differ in length App2    
 C:\Workspaces\Sandbox\App2\App2\obj\Debug\90\android\src\crc64bb1b55f618e11607\myNotificationManager.java


I understand the message but according to the dotnet documentation: NotificationManager Constructor the type of the constructor's parameters is IntPtr and JniHandleOwnership not Context and Handler.

From the Android documentation I dont see any public constructor

Android target framework version: v9.0 (API 28)
Android SDK Plateform installed: 28,29,30


dotnet-xamarin
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.

1 Answer

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered JessieZhang-2116 commented

Hello,


Welcome to our Microsoft Q&A platform!

If we click into the source code of NotificationManager.cs in xamarin android ,we will find the function as follows:

77979-image.png

The type of class NotificationManager is static , so we can use NotificationManager in the following way:

         var channel = new NotificationChannel(CHANNEL_ID, name, NotificationImportance.Default)
                       {
                           Description = description
                       };
          var notificationManager = (NotificationManager) GetSystemService(NotificationService);
         notificationManager.CreateNotificationChannel(channel);


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.



image.png (19.4 KiB)
· 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.

Hi Jessie,

Thank you.

Yes, I notice I’ve never seen any instanciation of this class, only cast.

I want to put my logic between NotificationManager and all my apps, that's why I try to inherit from this class. There is no way for me to override all the virtual methods in NotificationManager ?

Thanks for your help.

0 Votes 0 ·

What kind of functionality do you want to achieve? Can you elaborate on that?

0 Votes 0 ·

Send push notification when app is closed and in-app notification when she's open.

0 Votes 0 ·
Show more comments