Android – Bluetooth App for receiving data and displaying

androidbluetooth

I'm developing a Bluetooth app for android that receives data and displays it. The functionality of the app is only to received data over Bluetooth and display it. I'm new to android so need help.

I have gone through the Bluetooth chat sample code.I have a query. The service used here is used for both sending and receiving data. But my app will only receive and display. There is no sending. Can anyone help me how to do the modification? Please provide the code changes.

Best Answer

You can just use the Bluetooth Chat example as it is, but in your receiving application you would very simply never call the sendMessage() method.

The main Activity in the Bluetooth Chat example is BluetoothChat.java. For your receiving application, you can start with this Activity as the basis of your own Activity, modifying it so that it displays incoming data in whatever format you wish, instead of using the ListView. Because your application will never send data, you would never ever call sendMessage(). If you really wanted to, you could delete the sendMessage() method, and delete the EditText that's used to write outgoing messages. And so on.

As it happens, last weekend I used the Bluetooth Chat example to turn my Archos 101 into a car lap time notice board at a car trackday event I organise. I positioned my Archos 101 where people could see it, and I sent the laptimes to it over Bluetooth from my HTC Desire. At both the transmitting and receiving end I simply used the Bluetooth Chat code as the basis. In the transmitting application, I only used sendMessage() to send out the lap times; any messages that might have been received in handleMessage() were simply discarded. In the receiving application, sendMessage() was never used, and I only read data bytes out from the MESSAGE_READ case in handleMessage(). Data read out from there were then stored to SQLite and also displayed within a Table layout.

Related Topic