How to call missing C# API implementations in MAUI

Paul K 0 Reputation points
2023-03-16T10:56:11.52+00:00

Hey guys,
I work with .NET 7 MAUI Blazor and use the android API 33.
I noticed that some features of the native android API are not implemented yet. (e.g. the method "registerSoftApCallback()" in the WifiManager or the Builder in SoftApConfiguration).

With the help of reflection it is possible to access those methods or create instances, but now I need to implement my own "SoftApCallback"-class has to use the native interface in wifiManager (missing in .NET 7). I have no idea how to do that with reflection..

Is there a way how I could extend the .NET classes? I also tried things like this:

        [Register("android/net/wifi/WifiManager$SoftApCallback", DoNotGenerateAcw = true)]
        public interface ISoftApCallback : IJavaObject
        {
            [Register("onStateChanged", "(II)V", "GetOnStateChanged_IIHandler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
            void OnStateChanged(int state, int failureReason);

            [Register("onConnectedClientsChanged", "(Ljava/util/List;)V", "GetOnConnectedClientsChanged_Ljava_util_List_Handler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
            void OnConnectedClientsChanged(Java.Util.IList clients);

            [Register("onInfoChanged", "(Ljava/util/List;)V", "GetOnInfoChanged_Ljava_util_List_Handler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
            void OnInfoChanged(IList<object> softApInfoList);

            [Register("onCapabilityChanged", "(Ljava/util/List;)V", "GetOnCapabilityChanged_Ljava_util_List_Handler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
            void OnCapabilityChanged(IList<object> softApCapabilityList);

            [Register("onBlockedClientConnecting", "(Landroid/net/wifi/WifiClient;)V", "GetOnBlockedClientConnecting_Landroid_net_wifi_WifiClient_Handler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
            void OnBlockedClientConnecting(object client);
        }

but had no success in the end. If I implement the interface with my own class the error says "cannot find symbol android.net.wifi.WifiManager.SoftApCallback".

How can I create a binding to the native android api in C#? I also had no luck with the metadata.xml approach in MAUI yet.

Developer technologies .NET .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. rodrigo bueno flores 0 Reputation points
    2023-03-16T11:27:45.6666667+00:00

    [Register("android/net/wifi/WifiManager$SoftApCallback", DoNotGenerateAcw = true)]

        public interface ISoftApCallback : IJavaObject
    
        {
    
            [Register("onStateChanged", "(II)V", "GetOnStateChanged_IIHandler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
    
            void OnStateChanged(int state, int failureReason);
    
    
            [Register("onConnectedClientsChanged", "(Ljava/util/List;)V", "GetOnConnectedClientsChanged_Ljava_util_List_Handler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
    
            void OnConnectedClientsChanged(Java.Util.IList clients);
    
    
            [Register("onInfoChanged", "(Ljava/util/List;)V", "GetOnInfoChanged_Ljava_util_List_Handler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
    
            void OnInfoChanged(IList<object> softApInfoList);
    
    
            [Register("onCapabilityChanged", "(Ljava/util/List;)V", "GetOnCapabilityChanged_Ljava_util_List_Handler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
    
            void OnCapabilityChanged(IList<object> softApCapabilityList);
    
    
            [Register("onBlockedClientConnecting", "(Landroid/net/wifi/WifiClient;)V", "GetOnBlockedClientConnecting_Landroid_net_wifi_WifiClient_Handler:Android.Net.Wifi.WifiManager/ISoftApCallbackInvoker, Mono.Android, Version=33")]
    
            void OnBlockedClientConnecting(object client);
    
        }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.