I created a new Xamarin.Forms app to test basic Bluetooth functionality. I downloaded this plugin into both the Android project and the shared project:
https://github.com/aritchie/bluetoothle
I wrote this function in the shared project and am calling it from the OnCreate
of my launch activity in my Android project:
public static async Task BroadcastBluetooth()
{
// (I do not await this function when I call it)
try
{
await Task.Delay(5000); // just to make sure we give enough time for all initialization to complete
_server = CrossBleAdapter.Current.CreateGattServer();
// exception thrown on this line
await _server.Start(new AdvertisementData
{
LocalName = "TestServer",
ServiceUuids = new List<Guid>()
});
}
catch (Exception e)
{
}
}
It throws this exception:
{System.NullReferenceException: Object reference not set to an instance of an object. at Plugin.BluetoothLE.Server.GattServer.StartAdvertising (Plugin.BluetoothLE.Server.AdvertisementData adData) [0x00095] in C:\dev\acr\bluetoothle\Plugin.BluetoothLE.Android\Server\GattServer.cs:135 at Plugin.BluetoothLE.Server.GattServer.Start (Plugin.BluetoothLE.Server.AdvertisementData adData) [0x00011] in C:\dev\acr\bluetoothle\Plugin.BluetoothLE.Android\Server\GattServer.cs:70 at App2.App+d__7.MoveNext () [0x00097] in C:\Projects\app2\App2\App2\App.xaml.cs:49 }
I'm only doing something really basic so I must be missing something? The exception is referencing a directory path of the plugin's developer's machine (C:\dev\acr...) so either this plugin is broken or I'm doing something really wrong?