Bluetooth liste of devices deosn't work anymore

Hello
2 years ago i had an APP inventor ap driving a led with an HC05 Module through Arduino
My apk is still working very well but if i build the same source and dowload the apk on my Android 13 Samsung S21, no more bluetooth devices are detected....
Do you have an idea of what happen ?

Thanks a lot for your help
David

(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.



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:

3 Likes

Hello ABG,

So cool ! thanks a lot for your answer wich solve my problem.

I'm teacher in france and i had a look in your improvement proposition but look a litlle bit complicate for my pupiles.

However can you explain me the purpose of the three blocs and why your proposition is better than the simple one ?

Best Regards

David

Since Api31 android has introduced new bluetooth permissions at runtime, for this we need the ApiLevel procedure to check what Api level we have. If it is api31 or higher it will ask for permissions, if the level is lower it will load devices into the list. If you request permission in API less than 31, an error will be displayed in the application. To be able to list bluetooth devices in api31 or higher, we need the BluetoothScan permission. An appropriate message will be displayed in the application asking us to confirm permissions. After confirmation, the PermisionGranted event will be triggered, in which we load devices to the list and ask for the next BluetoothConnect permission that will be needed in subsequent appinventor blocks where we want to connect to the selected device. We also save the appropriate tag to TinyDb so that the next time the application is launched, it does not ask for permissions again but loads the devices to the list immediately. You can simplify the blocks, but this will not guarantee operational stability,

2 Likes

Like @Patryk_F said

1 Like

These are not my original blocks and I have posted many examples and solutions for the BluetoothClient component (as well as the BLE extension) in the past months.

My blocks always looked or should look something like this:

Scanning for devices is only possible after both permissions (SCAN & CONNECT) have been granted (on Android 12+, tested on Pixel 4 XL / Android 13).


With your blocks I get a permission error, "Error 908: The permission ..."

2 Likes

To check it out, here are two AIAs.
BTclient_test1.aia (7.5 KB)
BTclient_test2.aia (7.5 KB)

BTclient_test1.aia uses your blocks and doesn't work. BTclient_test2.aia uses my blocks as I always posted them. This works. So build the APKs and check it on Android 12+...


And this version works with Companion & APK:

The extension GetASD can be found here

1 Like
Bluetooth device list not showing
Bluetooth list not seen
Bluetooth can't run on Android 12, but can run on Android 8
Error 908: The permission BLUETOOTH.CONNECT has been denied
The app does not connect to bluetooth
Error 507: Unable to connect. HC-05
Error 908 and Error 507
HC- 05 Bluetooth Module
My app don't show the bluethooth list
Connexion bluetooth with Arduino: problem between companion and .apk
Crash a la hora de conectar el bluetooth
Meu celular não está listando os dispositivos bluetooth
ListPicker Not Showing Bluetooth Devices with an Arduino Uno R3
Where to download working Bluetooth classic extension without permission problems
No aparecen elementos en la lista del bluetooth
AskForPermission (Bluetooth)
Bluetooth aplication does not connect
Calling list picker to open doesnt work whhen apk is built
Problema con la conectividad del bluetooth
Translator output does not show
I can find my bluetooth device when i went to select as device
The app does not connect to bluetooth
App not responding
The app does not connect to bluetooth
Bluetooth device is not found
Click on Notification
How do I Make my app ask permissions for nearby devices using bluetooth
Keep getting Error 515: Not connected to a Bluetooth Device
Bluetooth model list not released
Need help with ESP32 Servo control app
App doesn't connect with project
MIT App Inventor version nb198
Probleme bluetooth
BLE bluetooth scan
Error 908, con el HC-05
It kept going well, but it suddenly says error 515
I can't see devices to connect bluetooth
Something is wrong UV sensor, Bluetooth ardiuno , and Mit app
Hola tengo un problema con mi aplicación de app inventor no quiere conectarse a mi bluetooth hc0
I need help i think i noticed that bluetooth doesnt work with newer version of android
How to Create an MIT APP code blocks that can read the battery percentage of the battery that is powering up our arduino nano?
I need help i think i noticed that bluetooth doesnt work with newer version of android
How do I list bt devices?
My app don't show the bluethooth list
Bluetooth app with HC 05 to control robot
Help Needed with Bluetooth Server/Client Setup on Android 12 and 13
Help Needed with Bluetooth Server/Client Setup on Android 12 and 13
Two mobiles. Connection Server - Client by Bluetooth. LDR trigger a relay
Bluetooth no longer works on API 12,13 and probably 14. I'm having difficulties
Two mobiles. Connection Server - Client by Bluetooth. LDR trigger a relay
Can i connect bluetooth by using listview ? any one plese tell me
BLUETOOTH CLIENT not connecting in HC-05 with arduino
Pourquoi le listpicker ne me propose pas les bluetooth
Error 507: Unable to connect. Is the device turned on
Android JDY-016 bluetooth error 507
The .apk run in BlueStacks not work
Error 507 on HC-05 module
Error 507 on HC-05 module
FAQ section: FAQ
The ProCamera not take picture?
Error 507 unable to connect is the device turned on?
Im getting a error 507
Unable to Connect MIT App Inventor Application to HC-05 Module
TextToSpeech Component BUG
Can anyone help me blocks for classic bt for ANDROID 11
What Magic Is Needed to Get an MIT App to Connect to HC-05?
HC-05 bluetooth not working
Bluetooth code not working
Cant see bluetooth device when install .apk
App works with companion, but the apk doesn't work
Black Screen while trying to connect?
The application does not see the HC-06 bluetooth
The application does not see the HC-06 bluetooth
Black Screen while trying to connect?
Rx text bluethooth
Error 507 hc 05 bluetooth module continuation
The matching bluetooth list does not appear in listpicker in the latest android versions
Problem with Bluetooth connection
Bluetooth connection
Bluetooth list seems to be functioning correctly in terms of its underlying functionality, such as detecting devices and establishing connections. However, there is an issue where the list itself is not visible or not displayed properly
Problem with Bluetooth connection
Error 908: The Permission BLUETOOTH.CONNECT has been denied (android 11)
Error 908: The Permission BLUETOOTH.CONNECT has been denied (android 11)

Corrected boiler plate:

(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:

See Bluetooth liste of devices deosn't work anymore - #7 by Anke
Special note for Xiaomi devices:
I have an error with bluetooth on android 12, Xiaomi Poco X3 NFC - #20 by Patryk_F

Regarding "External Inputs" and "Inline Inputs":

inlineInputs

3 Likes

Dear Anke
Thanks a lot for the fantastic code.
I have tried it and add some flowers around it.

  1. I have 2 questions on two points in the following picture.

  2. I succed in connecting my BT module, but the list of BT devices is still displayed in Screen1. How to hide it after the selection of my BT module ?

Thanks in advance for your help.
PS : here is my aia :
BTclient_test2+DRFlowers.aia (8.1 KB)

  1. One is without extension and the other is an extension.

  2. I explicitly pointed out this problem in my answer(s) to ABG. So please read this again. (I deliberately left this block there "grayed out" to point out the problem and the solution.)

  3. Use a timer to hide the ListView once a connection is established.

Summary

1 Like

Is there a penalty from Android for asking for a permission that has already been granted?

I'm not sure but a feel like your question is a litle bit ironic ?

Thanks a lot for your wise help.
Things are a litlle bit clearer for me but i still have a basic issue.
I'm trying to send a 2 bytes Number 513 but not able to receive the correct number in Arduino serialDisplay. I read lot of discution but still don't understand where i screw up ?


No, I am just rummaging for a way to reduce the complexity of getting permissions without having to remember asking for it or without having a way to ask Android if I already have permission.

I'm searching for an easy stock answer for the board, without the experience of the people with actual experience.

you can try to ask as much as you like for permissions...

if you already have a permission, you do not get the permission window anymore and the event PermissionGranted does not fire anymore... because of the latter it might be a good idea to know if you already have that permission

Taifun

As I've said often enough, Google makes life more difficult for all of us – every year again with these (mandatory) idiotic targetSdkVersion updates. As long as users and developers just put up with this BS, this probably won't change. Btw, all Android users face these problems, not just AI2 users.

Sending 513 and receiving the sequence 0,120,128 is a bit of a puzzle.

Using Google to convert for me, 120 in binary is 1111000.
128 in binary is 10000000

But binary for 513 is 1000000001.

So where did that sequence of 1's in the 120 come from?

The BTSerial.begin(38400) is asking for a high bit rate.
Would lowering it to a more common 9600 fix bit errors?

1 Like

Thanks a lot for your answer.

I 've checked your remarks regarding BTSerial speed and lower it @9600.
I've also changed 513 to 512
I've also replace BTSerial by the embedded Serial channel, but same results.
Please find bellow results of my tests, and obviously the transmission BTserial speed has change something but still don't understand.




I feel that the issue is around sending and receiving 2 bytes because i've also tested communication with 1 byte and it work in a very nice way.


Look around in the BlueToothClient blocks pallette for more transmission modes (integer, text, etc.)

Try those and see what arrives.