I am having trouble connecting two Android devices via Bluetooth, which happens only when they have been paired before. I am running one as the server and the other as the client.
Here is the sequence of things on the server side:
On the client side:
The above process works perfectly fine for me when the client and the server have never been paired before. However, after Android registered them in the device list, they will inevitably timeout at the connect()/accept() stage.
I have been searching for a solution for a couple days now and have tried quite a few things including this one: Connecting to a already paired Bluetooth device
The reflection method does not work for me either. It seems that connect() would return immediately but when I tried to getOutputStream() I get an exception. On the accept() side it does not even register that someone tried to connect. I seriously need some help or pointer on getting the devices to establish a connection once they have been paired before.
Here is some info about the devices:
Thank you ahead of time. I am about 2-week-old in Android and Bluetooth, so if you see any missing steps or best practices, please point them out as well.
Go to settings, Bluetooth, and find your speaker (There should be a list of Bluetooth devices that you last connected to). Tap on the Bluetooth speaker to connect, then turn the speaker on AFTER you pressed the connect button, while your device is trying to connect to it.
Android users need to go to Bluetooth Settings and pair either Bluetooth headphones or speakers one by one. Once connected, tap the three-dot icon on the right and click on Advanced Settings. Toggle on the 'dual audio' option if not already turned on. This should enable users to connect to two devices at once.
Can someone connect to my Bluetooth without me knowing? Theoretically, anyone can connect to your Bluetooth and gain unauthorized access to your device if the visibility of your Bluetooth device is on.
Try unpairing, then re-pairing, the device. To unpair a device, select Start , then select Settings > Devices > Bluetooth & other devices . Select the Bluetooth device that's paired but not working, then select Remove device > Yes. After that, pair the device again.
In the client when I attempt to make a connection to a bonded device, I simply called it on the BluetoothDevice I found in BluetoothAdapter.getBondedDevices()
. This does NOT work.
In order to properly establish the Bluetooth connection, I had to do something similar to the pseudocode below:
BluetoothDevice bonded = a device from BluetoothAdapter.getBondedDevices();
BluetoothDevice actual = BluetoothAdapter.getRemoteDevice(bonded.getAddress());
BluetoothSocket socket = actual.createRfcommSocketToServiceRecord(SOME_UUID);
socket.connect();
I arrived this answer by following exactly the Bluetooth chat example: Bluetooth Chat Service. Why it doesn't work on the device from getBondedDevices()
is beyond me. Maybe someone with more intimate knowledge of Android can answer that.
Check out this example: http://developer.android.com/resources/samples/BluetoothChat/index.html.
this could explain how the bluetooth device connected and trans informations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With