I already successfully paired my Android (6.0.1) phone (Sony Xperia Z3) with my laptop (running Ubuntu 14.04). I can send files back and forth. The Bluetooth connection menu shows that the connection switch switches to ON if files are sent.
I established a persistent connection using:
sudo rfcomm connect rfcomm0 [MAC ADDRESS] [CHANNEL]
I want to send data from my phone to my laptop via Bluetooth. If I run this code the switch goes on as well, but immediately closes the connection down (switch goes back to OFF).
Logcat shows the following warning after calling init()
:
W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
and upon calling the write()
method this exception:
E/error: error init:java.io.IOException: read failed, socket might closed or timeout, read ret: -1
When connecting using rfcomm
some channels fail and refuse the connection. My guess is that I am using the wrong channel.
- How can I know which channel to use when calling
rfcomm
? - How can I specify this channel in my Android app?
- How can I know which UUID to use?
- In the example code the first UUID is used: why?