Unable to compile class implementing MediaNotification.IProvider.CreateNotification()

Open
#1,106 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
android, csharp
Domain
mobile, tooling

Research direction

Start with the generated binding at obj\Debug\net9.0-android\android\src\crc64c44f8a9ee386df14\MediaNotificationProvider.java and compare its createNotification signature with MediaNotification.IProvider.CreateNotification and the AndroidX.Media3.Session.MediaNotification.IProvider documentation. Reproduce the build using a new .NET Android class implementing the interface; done means the generated Java class overrides createNotification and the project compiles.

Written by the indexing model from the issue text.

Description

Android framework version

net9.0-android

Affected platform version

Visual Studio Enterprise 2022 v17.13.1

Description

I am trying to create a class implementing the AndroidX.Media3.Session.MediaNotification.IProvider interface but the IProvider.CreateNotification() function signature doesn't appear to match the Android signature and it won't compile. This is what VS insists is the required declaration of the CreateNotification() function implementation...

    public class MediaNotificationProvider : Java.Lang.Object, MediaNotification.IProvider
    {
        public bool HandleCustomCommand(MediaSession? p0, string? p1, Bundle? p2)
        {
            return true;
        }

        MediaNotification? MediaNotification.IProvider.CreateNotification(MediaSession? mediaSession, Java.Lang.Object? mediaButtonPreferences, MediaNotification.IActionFactory? actionFactory, MediaNotification.IProviderCallback? onNotificationChangedCallback)
        {
            throw new NotImplementedException();
        }
    }

... but when I try to compile this I get these two error messages...

obj\Debug\net9.0-android\android\src\crc64c44f8a9ee386df14\MediaNotificationProvider.java:4: error: MediaNotificationProvider is not abstract and does not override abstract method createNotification(MediaSession,ImmutableList<CommandButton>,ActionFactory,Callback) in Provider
public class MediaNotificationProvider
       ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

and

error: MediaNotificationProvider is not abstract and does not override abstract method createNotification(MediaSession,ImmutableList<CommandButton>,ActionFactory,Callback) in Provider
public class MediaNotificationProvider

According to the Android documentation the mediaButtonPreferences argument should be type ImmutableList<CommandButton> but trying the .net version of that doesn't work either and generates the error...

'MediaNotificationProvider.CreateNotification(MediaSession?, ImmutableList<CommandButton>?, MediaNotification.IActionFactory?, MediaNotification.IProviderCallback?)' in explicit interface declaration is not found among members of the interface that can be implemented

I am guessing the binding is not correct but I'm not familiar enough with .net Android bindings to understand what is going on.

Steps to Reproduce
  • Right click on existing .net-android project and choose Add->New Item to create a new class
  • Change class to inherit from Java.Lang.Object and MediaNotification.IProvider
  • Start typing "MediaNotification.IProvider.Create" and then hit tab to accept the suggested code for CreateNotification()
  • Attempt to build your code
Did you find any workaround?

No response

Relevant log output

Dominant language
C#
Stars
318
Forks
73
Avg merge
2d 6h
Merged PRs (30d)
10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/android-libraries

All issues in dotnet/android-libraries

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.