Skip to content Skip to sidebar Skip to footer

Bluetooth Socket Not Connecting, Unable To Pair Devices

I'm learning android and working on an project's app which uses Bluetooth. I was already able to discover and list devices. But when I try to pair devices, socket.connect() fails

Solution 1:

first you have to create BluetoothServerSocket with this method listenUsingRfcommWithServiceRecord() with the use of BluetoothAdapter:

BluetoothServerSocket mServerSocket = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);

then you can create

BluetoothSocket socket = mServerSocket.accept();

and then use

socket.connect();

After connecting with this method you have to do as below:

BluetoothDevice device = socket.getRemoteDevice();
BluetoothSocket tmp = device.createRfcommSocketToServiceRecord(DEVICE_UUID);
tmp.connect();

So let me clear you that you are using createRfcommSocketToServiceRecord() method directly and try to connect socket but instead of that try this way. i hope it will clear your doubts now.

But please remember that, listenUsingRfcommWithServiceRecord() is long background process method so take care it with thread or async task. hope it helps. thanks!!


Post a Comment for "Bluetooth Socket Not Connecting, Unable To Pair Devices"