Adham
Adham

Reputation: 64844

How to communicate android application with Bluetooth-enabled device?

What is the required to allow android application to communicate with Bluetooth-enabled devices (that uses the easy Bluetooth module)?

Do I need to use the normal BluetoothAdapter class . I have tried the chat example attached with android samples. But the android application can't discover the Bluetooth device ? What is the problem , do I need to use Bluetooth profiles ?

Upvotes: 0

Views: 1781

Answers (1)

iTech
iTech

Reputation: 18440

Typically these modules using Serial profile, so you can use BluetoothAdapter normally. I've a similar module that is attached to a micro-controller and it is working fine with Android app.

  • Make sure that the module is running in the "Slave" mode if it is configurable.
  • Search for the module from Bluetooth settings and pair with it before running your application.

Here is a quick code snippet to connect to a known device over Serial profile

String BTAddress = "ADD YOUR REMOTE DEVICE BLUETOOTH ADDRESS HERE"; // has the format 00:00:00:00:00:00
UUID SERIAL_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
BluetoothDevice btDevice = btAdapter.getRemoteDevice(BTAddress);
btSocket = btDevice.createRfcommSocketToServiceRecord(SERIAL_UUID);
btSocket.connect();

Upvotes: 2

Related Questions