dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 531 forks source link

Notification.Action#icon field is missing #3632

Closed CarlosACepeda closed 2 years ago

CarlosACepeda commented 5 years ago

Steps to Reproduce

Hello, I'm currently making an app that controls Notifications, I need to retrieve the Icons for the Notification Action buttons, so I use the property 'Icon' to retrieve them, however it only works in API Level 23 in Marshmallow and onwards because in previous versions the field 'icon' is used instead, that returns an int pointing to a resource. Notification.Action class does not have this field, so making impossible for my implementation to get the Notification Action button icons in Android Versions prior to 23. (Marshmallow)

Expected Behavior

Notification.Action class should have the 'icon' field that returns an int when the API level is between Kitkat and Lollipop.

Actual Behavior

The field does not exist and the Property 'Icon' causes an exception of 'NotSuchMethodFound' when trying to retrieve the Action Icon int (for example on Kitkat)

Version Information

Microsoft Visual Studio Professional 2017 Versión 15.9.10 VisualStudio.15.Release/15.9.10+28307.557 Microsoft .NET Framework Versión 4.7.03190

Versión instalada: Professional

Visual C++ 2017 00369-60000-00001-AA732 Microsoft Visual C++ 2017

Administrador de paquetes NuGet 4.6.0 Administrador de paquetes NuGet de Visual Studio. Para obtener más información acerca de NuGet, visite http://docs.nuget.org/.

Asistentes de Microsoft Visual C++ 1.0 Asistentes de Microsoft Visual C++

ASP.NET and Web Tools 2017 15.9.04012.0 ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.8.31590 Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2012 4.0.30625.0 For additional information, visit https://www.asp.net/

ASP.NET Web Frameworks and Tools 2017 5.2.60913.0 Para obtener información adicional, visite https://www.asp.net/

Azure App Service Tools v3.0.0 15.9.03024.0 Azure App Service Tools v3.0.0

Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio 2.3.3000.2 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 15.9.02046.0 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.3.3000.2 Microsoft Azure Stream Analytics Tools for Visual Studio

Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Extensión ResourcePackage 1.0 Detalles de la extensión ResourcePackage de Visual Studio

Extensión ResourcePackage 1.0 Detalles de la extensión ResourcePackage de Visual Studio

Fabric.DiagnosticEvents 1.0 Eventos de diagnóstico de Fabric

GitHub.VisualStudio 2.9.1.7781 A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

Herramientas comunes de Windows Azure 1.10 Ofrece servicios comunes para su uso con los servicios móviles de Microsoft Azure y Microsoft Azure Tools.

Herramientas de C# 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a Componentes de C# que se usan en el IDE. Puede que se utilice una versión distinta del compilador en función de la configuración y del tipo de proyecto.

Herramientas de entrega continua de Microsoft para Visual Studio 0.4 Configuración simplificada de las canalizaciones de Azure DevOps desde el IDE de Visual Studio.

Herramientas de Microsoft Azure Service Fabric para Visual Studio 2.4 Herramientas de Microsoft Azure Service Fabric para Visual Studio

Herramientas de TypeScript 15.9.20918.2001 Herramientas de TypeScript para Microsoft Visual Studio

Herramientas de Visual Basic 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a Componentes de Visual Basic que se usan en el IDE. Puede que se utilice una versión distinta del compilador en función de la configuración y del tipo de proyecto.

Herramientas de Visual F# 10.2 para F# 4.5 15.8.0.0. Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691. Herramientas de Microsoft Visual F# 10.2 para F# 4.5

JavaScript Project System 2.0 JavaScript Project System

JavaScript UWP Project System 2.0 JavaScript UWP Project System

MainWindow Extension 1.0 MainWindow Visual Studio Extension Detailed Info

Microsoft Azure HDInsight Azure Node 2.3.3000.2 HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service 2.3.3000.2 Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.3.3000.2 Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools 2.9 Microsoft Azure Tools para Microsoft Visual Studio 2017 - v2.9.0.0

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools para contenedores 1.1 Desarrolle, ejecute y valide sus aplicaciones de ASP.NET Core en el entorno de destino. Presione F5 para ejecutar la aplicación directamente en un contenedor con opción de depuración, o bien presione CTRL + F5 para editar y actualizar la aplicación sin necesidad de recompilar el contenedor.

MLGen Package Extension 1.0 MLGen Package Visual Studio Extension Detailed Info

Mono Debugging for Visual Studio 4.13.12-pre (9bc9548) Support for debugging Mono processes with Visual Studio.

Paquete del host de adaptador de depuración de Visual Studio Code 1.0 Capa de interoperabilidad para el hospedaje de adaptadores de depuración de Visual Studio Code en Visual Studio

Paquete Herramientas de Application Insights para Visual Studio 8.14.20131.1 Herramientas de Application Insights para Visual Studio

Paquete VC de Microsoft Visual Studio 1.0 Paquete VC de Microsoft Visual Studio

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

Servicio de lenguaje JavaScript 2.0 Servicio de lenguaje JavaScript

SQL Server Data Tools 15.1.61903.01040 Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter para Google Test 1.0 Habilita las herramientas de prueba de Visual Studio con las pruebas unitarias escritas para Google Test. Los términos de uso y los avisos de terceros están disponibles en el directorio de instalación de la extensión.

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

Visual Studio Tools para aplicaciones Windows universales 15.0.28307.556 Visual Studio Tools para aplicaciones Windows universales permite crear una experiencia de aplicación universal sencilla para todos los dispositivos que ejecutan Windows 10: teléfono, tableta, PC y más. Incluye el kit de desarrollo de software de Microsoft Windows 10.

Visual Studio Tools para CMake 1.0 Visual Studio Tools para CMake

Visual Studio Tools para contenedores 1.0 Visual Studio Tools para contenedores

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

Xamarin 4.12.3.81 (d15-9@780082716) Extensión de Visual Studio para habilitar la implementación de Xamarin.iOS y Xamarin.Android.

Xamarin Designer 4.16.13 (45a16efd4) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 1.1.128 (6f5ebb2) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.1.7.0 (HEAD/ba9da7a76) Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 12.2.1.16 (2dc06c7) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

gugavaro commented 5 years ago

@CarlosACepeda would be possible you provide a sample with your repro. I can see the Icon property available since Api Level 19. It was deprecated on 23 A repro project would be great for us to define next steps.

thanks!

CarlosACepeda commented 5 years ago

The setup for reproducing this case is quite complicated, however I think I didn't make myself clear. As the Xamarin.Android documentation says, the Icon Property is mapped to the method [getIcon()](https://developer.android.com/reference/android/app/Notification.Action.html#getIcon()):

image

Android Dev Website:

image

but this method is available since Marshmallow(23) as Android documentation states. If I need to get the icon when the device runs Kitkat(19)/KitkatWatch(20) or Lollipop(21/22) I should use the field named icon instead

Android Dev Website:

image

So I search for the equivalent of this field in the Xamarin.Android documentation in the class Notification.Action, but only the property Icon is found, but, as I said earlier, this property is mapped to the getIcon() method, that is available since Marshmallow(23), so in summary, in my implementation is impossible to get the icon int of the Notification.Action object when the Api Level is Between 19 and 22.

gugavaro commented 5 years ago

Thanks @CarlosACepeda , now I understand better the issue and I was able to repro it. I will be working on a fix for this issue.

For now, here is a quick and dirty workaround to unblock you. You can check the version and use the JniPeerMembers.InstanceFields to retrieve the correct field you are looking for.

actionObject is your Android.App.Notification.Action object


            // Check if the version is lower than Marshmallow
            if (Android.OS.Build.VERSION.SdkInt < BuildVersionCodes.M)
            {
                var actionValue = actionObject.JniPeerMembers.InstanceFields.GetInt32Value("icon.I", actionObject);
            }
            else
            {
                var actionValue = actionObject.Icon;
            }

let me know if you have any other question. thanks!

CarlosACepeda commented 5 years ago

Okay! I'll be implementing this workaround and give feedback, :)

CarlosACepeda commented 5 years ago

Verified and it works, thank you a lot, I'll be looking forward to see the solution, btw.

CarlosACepeda commented 2 years ago

Any news on this? @jpobst (now that @gugavaro is not in charge of this issue)

jpobst commented 2 years ago

Unfortunately, we never came up with any workable solution to allow fields and methods that have the same name when converted to C# to coexist. They all suffer from the issue this report shows.

For example, if we decided "if a method and field conflict, call the field XXXField", then that causes a breaking change when we originally had:

public int Icon = 0;

And then the method gets added:

public int IconField = 0;

public Image Icon () { ... }

All code that was previously relying on the field would be broken.

Going forward, we have implemented automated API compatibility checks, so that if this happens again in the future our build process will error, and we will have to do the required changes to keep the existing field/method so that compatibility is preserved.

CarlosACepeda commented 2 years ago

Now I see! Thanks for investing time into this issue! I guess this won't be fixed anytime soon hehe. 😅 Fortunately we still have JniPeerMembers to workaround cases like this and the Compatibility checks you've mentioned!