No Bluetooth Devices Found in .NET MAUI Using Plugin.BLE

Asad Ali 0 Reputation points
2024-09-08T12:44:19.72+00:00

Subject: No Bluetooth Devices Found in .NET MAUI Using Plugin.BLE

Hi community,

I’m developing a .NET MAUI application that uses Plugin.BLE to scan for Bluetooth devices. However, I’m encountering an issue where no Bluetooth devices are being detected during the scanning process, even though Bluetooth is enabled and working on my device.

Problem Description:

  • I’m using Plugin.BLE to scan for Bluetooth devices in my .NET MAUI app.
  • I've followed the documentation to handle Bluetooth permissions (Bluetooth Scan, Connect, and Location) on Android 12+.
  • Issue: Despite following all steps, no devices are found during the scan, and the DeviceDiscovered event is not triggered.
  • Platform: Testing on Android 12 device.

Troubleshooting Steps I’ve Tried:

  1. Verified that Bluetooth is enabled on the device.
  2. Granted Bluetooth Scan, Connect, and Location permissions as required for Android 12+.
  3. Monitored the logs (adb logcat) during the scan but did not see any specific error messages or discovered devices.
  4. Increased scan timeout to ensure the scan has enough time to discover devices.
  5. Used nRF Connect (a BLE sniffer tool) to verify that the Bluetooth devices are indeed broadcasting.

Code Snippet:

Here’s the relevant code I’m using for scanning:


_adapter.DeviceDiscovered += (s, a) =>

{

    Debug.WriteLine($"Device discovered: {a.Device.Name ?? "Unnamed Device"}");

    AvailableDevices.Add(a.Device);

};

await _adapter.StartScanningForDevicesAsync();

Additional Information:

  • Permissions: I’m handling permissions using ContextCompat for Android 12+ as suggested in the Plugin.BLE documentation.
  • Expected Behavior: The scan should find nearby Bluetooth devices (like my BLE printer), but nothing is being discovered.

Questions:

  1. What could be causing the scan to not detect any devices?
  2. Are there any additional permissions or setup steps required for Android 12+?
  3. How can I further troubleshoot this issue? Is there any way to confirm that the scan is running correctly?

Thanks in advance for any help!


Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-09-09T06:46:57.9533333+00:00

    Hello,

    Granted Bluetooth Scan, Connect, and Location permissions as required for Android 12+.

    Please add Manifest.Permission.BluetoothAdvertise as well. If your app makes the current device discoverable to other Bluetooth devices, declare the BLUETOOTH_ADVERTISE permission.

    And use ActivityCompat.RequestPermissions to request them like this similar thread:Bluetooth Plugin.Ble not showing any device.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.