BLE extension - Date Built: 2023-02-23 - permissions & connecting issuses on Android 12+

Yes do that. We'd love to see your "many devices" and if there are any problems with the devices being listed or whatever. And please post screenshots.

Both Apps works the same with me. Here are my screenshots:

Ok, looks fine. So what's the problem?
How many devices should there be? In other words, which devices were not listed?

No problem with that. The problem was the one I described before. Than you moved my topic to here, and I offered to test your apk. You told me to take a screenshot of it, and I've done. My topic has nothing to do with the main topic here, except that it's about improvements to the Bluetooth LE Extension.

I made an app that uses Bluetooth LE Extension. The App works great but when I am in an environment with too many devices (I think they use smoke detector with Bluetooth) the app gets very slowly, and I cannot choose my device. Does anybody know if there is a bug in this extension?
It's not possible to filter the devices by name before they will be written to the device-list, and I cannot filter out devices without name. Perhaps this is the problem. Perhaps this extension should be improved.

I cannot check whether the described problem will exist with the new extension because I don't have an environment with too many BLE devices here. This happens for example on fairs, where hundreds of devices were found.

That has nothing to do with the Extension and everything to do with the hardware's program. The program must include a name. If the manufacturer has applied a name, all of the detectors from one manufacturer will most likely have an identical name, which would be good for filtering-out (assuming only one or two detector manufactures). If, on the other hand, each device you want to list is actually named, then you can filter-in those which may be much quicker if you know the total number of devices as you can stop the scan once the required devices have been found.

I doubt this is the case but if the devices you wish to find are always the same ones, then a scan of available devices is not required. The App can store the device addresses and simply connect only with them.

Concerning the number of devices being in the hundreds, that is bound to slow down a Smartphone because of the intrinsic design of BLE itself. Use a Clock Timer to allow all the devices to be found and added to the list.

Okay, so the solution should be the following: All devices, I want to use, contains "BTG" in the name. So I scan for a specific short period of time, then stop the scan and add all devices that contains "BTG" in the name to a list. Then repeat the process to find more devices with the correct name and add them to my list – if not there yet. Right?

I'm wondering what environment do you want to scan/find devices in when there are tens or hundreds of devices available there. If previously found devices are known, they should be saved in a list (TinyDB) and it can then be queried which of the devices found during scanning (in an environment with many devices) are already contained in the saved list. Only devices that are already known can be listed.

So answer the question, what environment are we talking about, where dozens of devices can be listed. And which of these devices should be listed - for what reasons? And which other users might also have access to these devices during this time?

I admit that I haven't worked with the BLE extension very often, so I'm not familiar with all the possible scenarios. So what exactly is the aim/purpose of your app?

I don't see any device with "BTG" in the list (of your screenshot).
Btw, the .FoundDeviceName_index method seems to return an empty string. Is yours different?

Okay: I use a Powermeter that measures electrical measurements and give them via Bluetooth to an Android App. There is an ugly app from the manufacturer, so I sniffed the communication and made my own app. The Powermeters has different names, but all names contains BTG. The App includes a Bluetooth search that list all devices that contains BTG in the name. I choose one of them and the device is connected. The connected device is stored in the app cache and when I restart the app it will automatically search for this Powermeter.
Now, my problem happens when I try to use this Powermeter on a fair. The app starts to scan devices and put all devices to the BluetoothLE.DeviceList (that is generated automatically, when I use When BluetoothLE.DeviceFound) from where the app should copy the ones with the right name to my own list and select the right one to connect. But when there are too many devices around it crashed (or will get very very slowly - not useable anymore).

My though was that it should be possible to filter the devices before they are put to BluetoothLE.DeviceList to prevent that crash.

Hope my description was more understandable now :slight_smile:

Try something like this:

If that doesn't work either, try using a timer as @ChrisWard suggested.

My Block looks like this. I think I do nearly the same. (I use Buttons instead of a listview because the device needs to operate from an Android TV without touchscreen, too)

Well, your posts go in a direction that actually has nothing to do with the original topic anymore. So these should be moved to a new topic again - but not under the "Bugs" category.

Maybe some PU can do that, since I don't have much time at the moment.

What is interesting is that devices are found one-at-a-time. Snag is, the Extension, in an ideal environment, finds devices in a short space of time, possibly too quickly to test each as they are found, but we can try (untested code!):

BLE_Test.aia (195.9 KB)

I have asked MIT Guru Evan Patton if he can add a new function to the Extension to filter the BLE Device List on-the-fly. Note that we have never required this before so it isn't a priority - but since Evan is currently working on an Extension update, we might get lucky!

1 Like

Great. Thx, ChrisWard. Perhaps this will be solved with 2023 Bluetooth LE extension. I will try to make more experiments on the next fair. (Don't know how to simulate hundreds of BLE devices else...)

Do we know if nb191 gets the BLE permissions in the manifest right for Android versions below v12?

Yes, I think so. However, you must add at least one .Connect block to the Blocks area to get the android.permission.BLUETOOTH_CONNECT permission declared in the Manifest.

According to my tests, this permission is generally required, even if it's just about listing (scanning) BLE devices. (I've already pointed this out elsewhere and let @ewpatton know about it.)

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:maxSdkVersion="30" android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:maxSdkVersion="30" android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>

See also here:

1 Like

For Android 11 and earlier it does the same thing it always did. BLUETOOTH and BLUETOOTH_ADMIN were install time permissions so there wasn't a need to perform runtime permission requests. With Android 12+, we have to add new permissions (as discussed elsewhere) and ask for them at the appropriate times. The problem at the moment with the BLE extension is that one of the APIs we use in some properties actually requires CONNECT permission (e.g., DeviceList) even though we haven't actually connected to the device yet, such as when one presents the list of devices to pick from. In the next beta version I'll be adjusting the permissions to account for this.

2 Likes

Here is the screenshot of the apk application in the classic environment. But I don't understand the link between what you are asking me to do and the fact that all the aia applications used with the companion systematically cause the error message concerning Bluetooth. Can you explain to me the relationship between the


2 things please?

My test app (aia) on Android 13 with Companion:

Good morning, could you post or send me the .aia file of this apk [mod edit personal info removed, use the community Private Message feature instead]. Please