SurfaceCallback API is missing
vautieri2 opened this issue · comments
Android application type
Classic Xamarin.Android (MonoAndroid12.0, etc.), .NET Android (net7.0-android, etc.)
Affected platform version
VS2022
Description
Xamarin.Android does not seem to provide a wrapper for https://developer.android.com/reference/androidx/car/app/SurfaceCallback
This API is used for Android Auto
Steps to Reproduce
Try to use SurfaceCallback in a Xamarin.Android project
-> Doesn't compile
Look at the Xamarin docs, (not mentioned)
Did you find any workaround?
No
Relevant log output
No response
Xamarin.Android only provides bindings for Android's base framework android.jar
. To use AndroidX API you need to add the relevant NuGet binding package.
This API appears to be in this package:
https://www.nuget.org/packages/Xamarin.AndroidX.Car.App.App
I have 1.2.0.1 installed and have my app already working on their heads up display. I now need to add the surface callback. All I see exposed is ISurfaceCallback which does not have anything to override.
Looks like all the methods on the SurfaceCallback
interface are default
methods, which I don't think are currently exposed in AndroidX.
Yep, let's move this issue to the AndroidX repository.
Just curious as I have no idea how long it takes to get a nuget with this fix. I can use a nightly build (I think I saw these somewhere) since we are not releasing this for over a month. Any way to do a short term work around?
There are some challenges to work through before packages can be updated to support default interface methods, so I would not expect them in the short term.
You should be able to implement the needed methods in C# with the correct signature and mark them with the [Export]
attribute to force the correct Java Callable Wrapper to be generated. (Documentation)
This would look something like:
public void MySurfaceCallback : Java.Lang.Object, ISurfaceCallback
{
[Export]
public void OnSurfaceAvailable (SurfaceContainer surfaceContainer) { ... }
}
"This would look something like:" I'm getting surface callbacks now! So this seems to be a workaround.