简体   繁体   中英

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 ?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM