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,
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:
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+...
(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:
One is without extension and the other is an extension.
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.)
Use a timer to hide the ListView once a connection is established.
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
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.
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.