Closed FifthCloud closed 1 year ago
It looks like you are using the Bluetooth Classic library and trying to connect to Bluetooth Low Energy services. For that you need to use the InTheHand.BluetoothLE library.
Thanks for the help so far. Have updated the code to the following...
public async Task<IReadOnlyList<GattCharacteristic>> BLETest()
{
bluetoothDevice = null;
if(await Bluetooth.GetAvailabilityAsync()) // Always returns true;
{
RequestDeviceOptions requestDeviceOptions = new()
{
AcceptAllDevices = true
};
var devs = await Bluetooth.ScanForDevicesAsync(requestDeviceOptions); // with or without "requestDeviceOptions" returns 0 scan devices
// No matter what I do ScanForDevices doesn't return anything.
if (devs.Count == 0)
{
OnConsoleMessages?.Invoke("Scan came up empty. Nothing found.");
return null;
}
// .....
}
dev.Count always returns 0. What am I missing? Isn't await Bluetooth.ScanForDevicesAsync(requestDeviceOptions); this line of code a BLE function. According to the documentation it is stating this is BLE functionality.
Peter, what I am missing? Really trying to figure this out on my own, but I am such a beginner I am stumbling here and there.
Yeah, I was really close. The answer was this.
RequestDeviceOptions requestDeviceOptions = new()
{
AcceptAllDevices = true
};
var requestDevice = await Bluetooth.RequestDeviceAsync(requestDeviceOptions);
Was able to select the BLE device and see all the Gatt profiles. Appreciate the nudge in the right direction.
I am really loving this software. There is something that I am missing and I feel I am close to the answer.
I have a Maui app that I am trying to connect to a Bluetooth device: BLE Device. It comes with an app that I am able to connect and pass data to and from it. When I am trying to make my own app I can pair it with it, but I am unable to get the device connected.
AndroidManifest
Have added every single permission related to Bluetooth to make sure I didn't miss anything.
My function where I call the Bluetooth connection
From all the research I have been doing about Bluetooth permissions, I think it's normal I don't get any pop-ups stating if I want to accept Bluetooth permission. Not sure why I cannot connect. Does anyone have any insight? Feel as though I am really close.