philipplackner/BluetoothChat

Not scanning for API Version <= 30

Opened this issue · 5 comments

I have followed your youtube tutorial on this scanning application, and I found it really understandable and enjoyable.

However, When I run my code, as well as the source code from this repo, on my own device it doesn't seem to detect any devices.
FoundDeviceReceiver is never triggered. I found that this is probably due to the fact that I am running API 30 on my android device, so that permissions might be a bit different.

The first thing I noticed is that for API <= 30 you also need the BLUETOOTH_ADMIN permission. Furthermore, in the bluetooth controller you check for the BLUETOOTH_SCAN permission, but since this is a newer permission, on lower API's this will always trigger the return right?

I tried disabling the permission check completely, just to force the code execution for the startDiscovery(), but still nothing seems to happen. What should we do to make this code work for API <= 30?

The first thing I noticed is that for API <= 30 you also need the BLUETOOTH_ADMIN permission. Furthermore, in the bluetooth controller you check for the BLUETOOTH_SCAN permission, but since this is a newer permission, on lower API's this will always trigger the return right?

Yes, I have tried the tutorial as well and tested on a Lenovo Tab M8 running Android 11. No scanned devices appear, while I am able to see them in the Bluetooth Paring preferences of the device. Thinking it was my Project, I tried downloading the project and using it directly from Git, nothing either. I added the BLUETOOTH_ADMIN permission and still nothing. Using Android Studio Giraffe on MacOS Ventura

I just tried the app in a tablet with Android 12 and it recognized the list of scanned and paired devices perfectly, but when using a cellphone with android 11 it doesn't show anything. Could somebody fix this problem? Thanks

I have had similar problems on API 30. I managed to fix a get the first part of the tutorial working with the following changes:

  • Added a versión check [if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)] before using BLUETOOTH_SCAN and BLUETOOTH_CONNECT permissions. They are always returning not granted on API 30 (at least on my device)
  • Added the following permission BLUETOOTH_ADMIN and ACCESS_FINE_LOCATION with maxSdkVersion 30 on the AndroidMainifest.xml
  • Requesting the permission ACCESS_FINE_LOCATION on MainActivity on API level < 31

Hope it helps!

I also encountered the same problem, who can help me