I have searched this and other sites, have tried many different suggestions, but it seems that I'm stuck now with my try-and-error approach. Here is the simple code with which I have tried the following things on my Android HTC Desire X (Jelly Bean) in order to connect to my OBDII Bluetooth adapter (called "super OBD"):
1) Using the sample from http://developer.android.com/guide/topics/connectivity/bluetooth.html
public class BTConnector {
private final UUID MY_UUID = UUID.randomUUID(); // our applications UUID for BT
// but recommended by <http://www.socialledge.com/sjsu/index.php?title=F12:_OBD-II_Android_Monitor>
// UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
public void setupBluetoothCommunication() {
BluetoothAdapter mBluetoothAdapter = null;
BluetoothDevice mBluetoothDevice = null;
// Step_1: Get BluetoothAdapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}
// Step_2: Enable Bluetooth
if (!mBluetoothAdapter.isEnabled()) {
// Request the default Android Settings dialog to start for enabling BT
// done manually for now
}
// Step_3: Find our to be paired device (e.g. OBDII device)
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName().compareToIgnoreCase("OBDII") == 0) {
mBluetoothDevice = device; // Found our device
}
}
}
// 3b. OPTIONAL: Discover devices
// Step_4: Connecting to the device
BluetoothSocket mmSocket = null;
// 1) Using suggested Bluetooth socket -> is not workin
// mmSocket = mBluetoothDevice.createRfcommSocketToServiceRecord(MY_UUID);
// mmSocket.connect();
// UUID.fromString("00001101-0000-1000-8000-00805F9B34FB") causes IOException: Unable to start Service Discovery
// UUID.randomUUID() causes IOException: Service discovery failed
// 2) Using suggestion from <http://stackoverflow.com/questions/12384833/android-bluetooth-software-caused-connection-abort> can possibly connect:
Method m = null;
m = mBluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
mmSocket = (BluetoothSocket) m.invoke(mBluetoothDevice, 1);
OutputStream tmpOut = null;
// Get the input and output streams, using temp objects because member streams are final
tmpOut = mmSocket.getOutputStream();
OutputStream mmOutStream = tmpOut;
// Write out data
String ati_command = "ATZ" + "\r"; // also tried: "ATZ\\r", "ATSP0\r" , "ATI\r", or bytes: speed = "010D\r", temp = "0105\r"
mmOutStream.write(ati_command.getBytes()); // THROWS IOEXCEPTION "Software Caused Connection Abort"
...
}
...
}
I tried different Android software:
- android-obd-reader https://github.com/pires/android-obd-reader) does not work, but
- Torque does work (which shows that my OBDII adapter is functioning)
Does this information give a hint? I'm really looking forward for some tips.
Thank you very much in advance!