32feet icon indicating copy to clipboard operation
32feet copied to clipboard

32Feet.net Compatibility with Xamarin Android Watch OS

Open Guangyu-Joshua-Feng opened this issue 2 years ago • 7 comments

When I install 32feet to Xamarian for Android, the follow errors occur:

Error NU1202 Package 32feet.NET 3.5.0 is not compatible with monoandroid12.0 (MonoAndroid,Version=v12.0). Package 32feet.NET 3.5.0 supports:

  • net (.NETFramework,Version=v0.0)
  • net-cf (.NETFramework,Version=v0.0,Profile=CompactFramework)

How should I resolve this?

Guangyu-Joshua-Feng avatar Jun 22 '22 21:06 Guangyu-Joshua-Feng

The package InTheHand.Net.Bluetooth is the current version and supports Android

peterfoot avatar Jun 22 '22 21:06 peterfoot

Works out great! Thank you Peter.

Guangyu-Joshua-Feng avatar Jun 24 '22 00:06 Guangyu-Joshua-Feng

I used the code that works completely fine with 32feet.net and run it with the libaray you mentioned above. At the following lines I got an error:

BluetoothEndPoint ep = new BluetoothEndPoint(blueAddress, _serviceClassId);

Console.WriteLine("Connecting!");
client.Connect(ep);

Error Message: Error CS7036 There is no argument given that corresponds to the required formal parameter 'service' of 'BluetoothClient.Connect(BluetoothAddress, Guid)'

So is there a way to get around this error caused by the package change?

Guangyu-Joshua-Feng avatar Jun 24 '22 21:06 Guangyu-Joshua-Feng

client.Connect(blueAddress, _serviceClassId);

peterfoot avatar Jun 24 '22 22:06 peterfoot

Thank you so much for your help Peter! The problem above is resolved in the way you suggested.

Meanwhile, I ran into another issue caused by the package change that I have no clue after reading your code samples:

At the following lines during runtime I got an error: (I am trying to deploy this app on Android watch Wear OS Square API 28, Android 9.0)

Bluetooth client = new BluetoothClient();
for each (var item in client.DiscoverDevices()) {
    ......
}

Error Message: System.NullReferenceException: 'Object reference not set to an instance of an object.'

Visusal Studio highlighted "client.DiscoverDevices()" when error occurs at the debug mode.

So is there a way to get around this error?

Guangyu-Joshua-Feng avatar Jun 25 '22 15:06 Guangyu-Joshua-Feng

My code is the following and wanna run it on watch. The line client.DiscoverDevices() fails:

#define isServer
public class MainActivity : WearableActivity
    {
        TextView textView;
        int count = 0;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.activity_main);
            Button button = FindViewById<Button>(Resource.Id.dialog_button);
            textView = FindViewById<TextView>(Resource.Id.text);
            button.Click += delegate {
                
                String sent_message = bluetooth_Send(); // here is where I call the bluetooth sending code.
                textView.Text = string.Format("Message: {}. Sent {} times", sent_message, count++);

            };
            SetAmbientEnabled();
        }

        private string bluetooth_Send()
        {
            String sentMessage = "null";
            Guid _serviceClassId = new Guid("D8D0378635F844FC818FC62C17F63205");

            BluetoothClient client = new BluetoothClient();
            //BluetoothRadio radio = BluetoothRadio.PrimaryRadio;
            //radio.Mode = RadioMode.Connectable;
            BluetoothAddress blueAddress = null;


            IReadOnlyCollection<BluetoothDeviceInfo> devices = null;
            if (client != null)
            {
                 devices = client.DiscoverDevices();
            }
            


            //get devices
            Console.WriteLine("Enumerating Devices until the desired one");
            for (int i = 0; i < devices.Count; i++)
            //foreach(var item in client.DiscoverDevices())
            {
                ...

            }


            return sentMessage;
        }

Guangyu-Joshua-Feng avatar Jun 27 '22 19:06 Guangyu-Joshua-Feng

I'm not familiar with Wear OS, but for Android in general have you added the required permissions to your appmanifest and requested the required runtime permission? Some info here - https://github.com/inthehand/32feet/wiki/Permissions

peterfoot avatar Jun 30 '22 13:06 peterfoot