BLE disconnect is not working properly

Hi,

I made an app that receives data via BLE from a development board. The problem is whenever I press disconnect button from my app it says Bluetooth disconnected but in actual it is not disconnected unless I close the app. I have checked other topic where thy mentioned solution to disable timer and I did that but it is still the same. Every time I want to disconnect I must close the app. Is there any solution to this problem?

Possibly define a function in the script of the board and activate that from the App first.

Yes this is a possibility but I want to initiate disconnect from the app. Is there some bug in BLE extension or my app?

One more issue is the app name. It never get changed. I found a topic about clearing all the cache and data from the app and the name issue will be OK. But it is not like this I uninstalled all apps and things related to MIT app inventor and downloaded the app and installed again and the name was still same. This name was the from 1st project I created and now no matter what, this name will stick to apps unless I create a new project from scratch with a different name.
Even if I create a new project and import .aia the name will still be the same as the imported .aia So only solution is to create a new project from scratch.

Well that would be.......

It can be an issue to disconnect Bluetooth, and to know whether or not it has been disconnected when disconnection is applied. This is not an App Inventor thing, it's a Bluetooth thing.

You should never import a .aia into an aia.

I assume you are using an existing Project as a template for others - and perhaps that Project was not defined by you, since if it was, you would know how you named it in the first place right?

ChangeAppName

1 Like

What is your exact hardware setup?

  1. Phone make/Model/Bluetooth Version

  2. Development Board Make/Model/ Bluetooth Module ID.

  1. Samsung A51. Bluetooth version 5.0, A2DP, LE
  2. nrf52833DK. Bluetooth 5.2 multiprotocol radio

nRF52833 DK is a really nice board. Your phone is a good spec too - it started on Android 10, what version of Android are you running now?

Android Version 12.
Even if I close the app it will not disconnected I have to close the app from the background then it gets disconnected. I tested with nrf android application (nrf Connect for mobile) and it worked fine with this.

The BLE extension has not to my knowledge been tested with Android 12.

App Inventor itself does not officially support Android 12, you can't compile an App for 12 [API 31] yet but with the Bluetooth specs being good to go, I would expect disconnect to work. A new release of App Inventor will be out very soon (hopefully in just a few days time). That might make a difference.

Ok. But I have a MI PAD 4 that is running on Android version 10 with Bluetooth 5.0, A2DP, LE and having the same issue with disconnect.

Time to show us your Project, and your Script. Upload them here.

I'm away from my desk now, back in the evening, UK time.

Testing.aia (196.8 KB)
Sure no problem. I have attached the project.

...and the Script.

If another Power User takes a look, I suggest that taking the User to the Phones BT connection via Activity Starter would be a temporary work-around.

By Script you mean code for nrf52833?

I have never used activity starter. Checking on google gives a lot of things like classes and properties and this is confusing. Can you please show a blocks diagram for disconnecting to BT using activity starter.

Yes.

It takes the User to the BT settings, it does not automatically switch BT on or off.

Action: android.intent.action.android.provider.Settings.ACTION_BLUETOOTH_SETTINGS

Class:
com.android.settings.bluetooth.BluetoothSettings

This is the main script.
main.txt (5.0 KB)

Hi androidz

Does your App actually work? There is a lot of BT related code that is unnecessary, and bits such as a millisecond Clock Timer - is that really necessary?