App Inventor Extensions


Classic Bluetooth Extension SDK 34 ready!

See the App Inventor Extensions document about how to use an App Inventor Extension.

For questions about this extension or bug reports please start a new thread in the App Inventor community. Thank you.

For feature requests please contact me by email. To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.

Nov 6th, 2016: Version 1: initial version

Jul 17th, 2017: Version 2: property DisplayRSSI added

Jul 23th, 2017: Version 2a: new build using extension-specific directory in aix file

Oct 21th, 2019: Version 3: for mac address method return default mac address for devices >= Android 8, SetDiscoverable method added

Oct 29th, 2019: Version 3a: Remove duplicates while scanning. Note: "display RSSI after scan" should be disabled for this to work!

Nov 10th, 2020: Version 4: property DisplayDeviceType added, API29 update concerning path to assets for companion app

Jan 7th, 2021: Version 4a: android.permission.ACCESS_FINE_LOCATION required starting from Android 10

Nov 4th, 2022: Version 5: SDK31 update: permissions android.permission.BLUETOOTH_CONNECT, android.permission.BLUETOOTH_SCAN and android.permission.BLUETOOTH_ADVERTISE added, new method RequestBluetoothPermission added, method MacAddress removed: to protect user privacy, on Android versions 6 and higher, access to the own MAC address is restricted to system apps. Third-party apps can't access it anymore.

Dec 10th, 2023: Version 5a: Extension rebuilt to avoid "ERROR: DX returned an error code" for projects, having 2 extensions or more which use proguard to obfuscate their code, see also Pull request 3004.

Feb 12th, 2024: Version 6: SDK33 update: methods Enable and Disable removed, users should now use the ACTION_REQUEST_ENABLE Intent, StartListeningStateChanged and StopListeningStateChanged methods added, State helper blocks added.
Note: This version is not compatible with previous versions. To update first remove the old extension, then import the new one.

Description

Bluetooth extension.
Minimum API version for this extension is API version 18, which is Android 4.3 (Jelly Bean MR2).
Required permission: android.permission.BLUETOOTH_ADMIN, android.permission.BLUETOOTH, android.permission.ACCESS_FINE_LOCATION, android.permission.READ_EXTERNAL_STORAGE, android.permission.BLUETOOTH_CONNECT, android.permission.BLUETOOTH_SCAN and android.permission.BLUETOOTH_ADVERTISE

Properties


Get DisplayRSSI, i.e. whether RSSI (Received Signal Strength Indication) should be displayed after Scanning.
Thank you Merciful for being the sponsor of this functionality.


Set DisplayRSSI, i.e. whether RSSI (Received Signal Strength Indication) should be displayed after Scanning.
Thank you Merciful for being the sponsor of this functionality.


Get Display Device Type, i.e. whether Device Type should be displayed after Scanning.
Thank you 18637 for being the sponsor of this functionality.


Set Display Device Type, i.e. whether Device Type should be displayed after Scanning.
Thank you 18637 for being the sponsor of this functionality.

Methods


Request Bluetooth Permission
This method will request the required runtime permissions
for devices > Android 11: android.permission.BLUETOOTH_CONNECT, android.permission.BLUETOOTH_SCAN, android.permission.BLUETOOTH_ADVERTISE, android.permission.ACCESS_FINE_LOCATION
for devices <= Android 11: android.permission.ACCESS_FINE_LOCATION


Get Bluetooth state.
Possible values: Bluetooth off, Turning Bluetooth off, Bluetooth on, Turning Bluetooth on, Unknown.


Enable Bluetooth

Note: In Android API 33+ this method is deprecated. Enabling/disabling bluetooth without user consent is not more possible. You should use android.bluetooth.adapter.action.REQUEST_ENABLE instead.




Disable Bluetooth

Note: In Android API 33+ this method is deprecated and enabling/disabling bluetooth without user consent is not more possible. You could use android.settings.BLUETOOTH_SETTINGS to open the settings for the user to disable bluetooth manually.




Scan Bluetooth devices.
Caution: Performing device discovery is a heavy procedure for the Bluetooth adapter and will consume a lot of its resources. If you already hold a connection with a device, then performing discovery can significantly reduce the bandwidth available for the connection, so you should not perform discovery while connected.

Note: if you use the flag "display RSSI after scan" you might get duplicates after scanning because the RSSI might change during the scan.
Note: if you use the flag "display display type after scan" you additionally will get the device type of the detected device, possible values are CLASSIC, BLE, DUAL, UNKNOWN.


Pair Bluetooth device. You will have to accept the connection on the other device manually.
This is currently an experimental block.


Unpair Bluetooth device.


Set device as discoverable. Duration is in seconds. The maximum duration is capped at 300 seconds for each request.


Start listening to bluetooth state changes.


Stop listening to bluetooth state changes.

Events


Event indicating that the bluetooth state changed.
Possible values: Bluetooth off, Turning Bluetooth off, Bluetooth on, Turning Bluetooth on, Unknown.


Event indicating that Scanning has finished.
As result two lists will be provided, a list with already paired devices and a list with new devices.


Event indicating that Pairing has finished.


Event indicating that Unpairing has finished.


Event raised after setting device to discoverable.


Event indicating that an error occurred.

Example App: Bluetooth Extension Test




Test

Version 6 tested successfully on Samsung Galaxy A54 running Android 14.

Questions and Answers

Q1: It's too long for search for devices, it lasts 60 seconds. It is possible to make search of devices with timing in seconds? For example to search for devices produced 3 seconds or 5 seconds so that the user himself could choose the time of search the Bluetooth devices.
A: Unfortunately this is not possible. The scan process takes its time. Also performing device discovery is a heavy procedure for the Bluetooth adapter and will consume a lot of its resources. Probably the Bluetooth Low Energy Extension by MIT offers a faster scan method. You might want to check...

Q2: When the Bluetooth device is connected to the phone, search TaifunBluetooth will no longer see the device. Is it possible to fix it?
A: If you are already connected, there is no need to scan for the same device, is it? Also if you already hold a connection with a device, then performing discovery can significantly reduce the bandwidth available for the connection, so you should not perform discovery while connected.

Q3: Is it possible to scan bluetooth without gps? I just need bluetooth classic.
A: According to my latest tests the runtime permission ACCESS_FINE_LOCATION is required to do a scan.

For questions about App Inventor,
please ask in the App Inventor community.Thank you.

Test the functionality of the Bluetooth extension

The test app is available in Google Play. You can test the example following these steps

  1. Follow the opt-in URL to get access to the app and to be able to download it to your device. It might take a few hours for Google to enable you as beta tester!
  2. Start testing.

Buy the Bluetooth extension for App Inventor


You can buy this extension (aix file).
With your payment you accept the terms and conditions below.

Payment options

1. Paypal

Please transfer 12 USD via Paypal
to Pura Vida Apps

2. Bitcoin

After having received your payment I will be happy to send the download link to you. Please let me know your Google account! I usually will send the download link not later than 24 hours after having received your payment.
Thank you! Taifun


Terms and Conditions

Back to top of page ...


Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact