BluetoothClient.AddessesAndNames works no more


Last year I developed a program on Arduino with Bluetooth board and and AppInventor app to talk to it through BluetoothClient. I could connect to that device and exchange data. Today the same app with the same Arduino doesn't display the Bluetooh board BUT only the already paired devices (which, in addition, are far from here).
How can I connect to a device (like a HC-08 ) which is not paired and can't be paired as usually I do with a phone? NOTE : if I use the app BLE Terminal, found on Google Play Store, it find the HC-08 board and talk using Serial comm.
Thank, Michele Di Bitonto

you forgot to ask for now necessary permissions...
Taifun

(Canned Response ABG - Bluetooth non-BLE SCAN Permission Blocks)

The easiest solution, for immediate relief
(from @Barry_Meaker) ...

I had the same issue. The problem is your app does not have permission to see nearby devices. The solution is to give your app permission on your phone (no code changes in your app).

on your phone,

  • goto settings
  • search for your app
  • in App Info for your app select Permissions
  • change Nearby Devices from Not Allowed to Allowed
  • Done

By the way, the very first time you run the app, Android will ask if you want to grant the app this permission. If you say no, or ignore the pop-up, the permission will be set as Denied. Android will not ask again.

A more complex approach, for professional app development:

These blocks can be dragged into your Blocks Editor to request permission(s) for Bluetooth non-BLE scanning and connecting. All three parts are needed.

You also will need to pull in TinyDB into your project.



When Permission Granted (@Patryk)

Thanks to @Anke for the original code.
My changes include

  • use of the Screen1 permission blocks to avoid the possibility of a typo
  • using a TinyDB tag particular to BT permissions and only for BT permissions.

(Thanks to @Patryk_F for correction to grant order)
Special note for Xiaomi devices:

Thank you a lot ; let me consider the following :

  1. I think the first solution can't be applied during appinventor development when the app isn't yet known by Android so
  2. I've seen the blocks to add in the app; unfortunately the the first one can't be dragged because it's just an image and the string in apilevel function isn't complete. Where can I find the complete string ? Or, alternatively, my Android version is 10; I think I can jump the search of the number associated and activate directly the RIGHT branch in Screen Initialize ? I'm going to try both unless you can suggest the right on associated to Ver. 10.

For example here

And here is the complete string

Taifun

Unfortunately, here I'm again. Looking at the csv file I can see that Android version 10 is associated to number 29; in this case I can cut the call to apiLevel in the 'if' instruction in the second group of instruction in the example you sent me. The flow moves directly through the 'else' branch. This means that all other instructions are useless. i.e. the flow is simply like my original one, without requests for permissions (I also canceled the tinyDB instructions). But, again, the list I get is the one already stored in the phone i.e. already paired devices, excluding the ones in the neighbourhood. Can't you try with a phone with Android version <12 ? Let me add a strange thing, I've developed another app with BLE 5.0 extension; If I launch this app, it sees the Arduino Bluetooth board.

Yes, using Bluetooth Client you only get the paired devices, see also the documentation Connectivity

AddressesAndNames

Returns the list of paired Bluetooth devices.

Taifun

You might be interested in the bluetooth classic extension

which can provide a list of paired and new devices after scanning

Taifun

Thank you again. I was just asking if what is written in the documentation is right and you has been faster explaining it. For a last experiment I will try to mix up the two ways of connectivity. The extension to get the list and the traditional, after getting the list from the other, to communicate to a device which has the old Bluetooth.
Bye Taifun

A question which doesn't necessarily need an answer during Sunday :
What did change in AppInventor about Bluetooth Client mgmt ? Around a year or two ago we could see a list of EVERY device around the phone, including NOT paired devices like HC-08 on Arduino BUT now we can see ONLY already paired devices preventing the use with the same devices that used to work before. Today the same app developed with AppInventor two years oag doesn't work and I can't use the same devices. I have to throw them away ! Anybody can answer this (maybe stupid) question ?

Not with the bluetooth client component, see again the documentation

It always was like that... this was one of the reasons I prepared the bluetooth classic extension to provide 1) a list of already paired devices and 2) a list of new devices

No, you do not have to throw anything away...

Taifun