In this Discussion

Bluetooth List devices array

Hello,
I have been looking at other examples on the forum of getting a bluetooth device connected on an Android device. I have the below code successfully working. I'm not using the popular Ketai library because I want to utilise RSSI signal and display all discoverable devices and RSSI signal strength on the canvas.

This is the point at which I am stuck. I have one discoverable device displayed and if a new device is discovered this supersedes the last one. However, I would prefer to add each discovered device into an ArrayList to get its name and its rssi info further up the draw loop for future drawing methods. I have the below code compiling but I don't think how I have written the ArrayList is correct as I am unable to access get() and size() in the draw loop.

In short I am not understanding my ArrayList method very well when used with the Bluetooth Android class.

Best Answers

Answers

Ok I have made some progress in looking at the backend java code of ketai library and how that accesses the ArrayList discoverable names.

I still cannot seem to instance the getDiscoveredDeviceNames().get(i) correctly in the draw loop so at the moment its doing nothing particularly useful. The aim is to associate an RSSI value to each new DiscoveredDeviceName.

code snippet tested (with required permissions): it works; i have simplified your code (and suppressed some errors: your background cannot never be seen as green!!!!) but you can now easily get all infos about blueTooth devices: could be better to make an arrayList of all blueTooth objects and methods to get name, mac adress, rssi and so on...Think to unregister your receiver onPause (with cancelDiscovery()); see also that rssi can change, or new devices be discovered: your text in draw() can be difficult to read!

@akenation --->
WoW! thank you. i really appreciate you taking the time to compile this for me. I don't think i would have gotten to the intentFilter part at all by myself. I will post a version here soon taking on board your advice about unregistering the receiver. Looking forward to utilising the discovered devices in interactive installation contexts. Thanks again