When I tried to connect two mobile phone from different manufacturer, those devices didn't connect. I developed an app which two Xperia phone, and bluetooth connect(ed) very well, (same as Samsung devices, between them). But, when I try to connect to an Sony Xperia and an Samsung phones, don't connect.
When I made this app I copy BluetoothChatService class form Google BluetoothChat Example (version 8) to my project (I didn't modify this file), but I have the above problem. So, I download the 10th api version Google BluetoothChat example and they connect the first time, but next times don't. The problem is Sony Xperia phone doesn't record bluetooht device info from Samsung phone and Samsung RECORDS this information.
01-18 11:29:07.036: D/BluetoothService(1744): B0:EC:71:E3:FB:41 bond state 11 -> 10 (9)
01-18 11:29:07.066: V/BluetoothEventRedirector(18829): Received android.bluetooth.device.action.BOND_STATE_CHANGED
01-18 11:29:07.066: E/CachedBluetoothDeviceManager(18829): Got bonding state changed for B0:EC:71:E3:FB:41, but we have no record of that device.
01-18 11:29:07.066: W/CachedBluetoothDeviceManager(18829): showUnbondMessage: Not displaying any message for reason:9
The next step was to unpaired two phones so I try those stackoverflow examples, and one of them fix this problem.
Now, I can do the connection from Sony Xperia U to Samsung Galaxy SII very well, but when I try to connect from Samsung SII to Xperia U don't connect because "refuse connection" message in IOExpection appear.
This is a copy from ConnectThread class of Google BluetoothChatService file example.
public void run() {
Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType);
setName("ConnectThread" + mSocketType);
// Always cancel discovery because it will slow down a connection
mAdapter.cancelDiscovery();
// Make a connection to the BluetoothSocket
try {
// This is a blocking call and will only return on a
// successful connection or an exception
mmSocket.connect();
} catch (IOException e) {
Log.i("INFO", e.getMessage());
// Close the socket
try {
mmSocket.close();
} catch (IOException e2) {
Log.e(TAG, "unable to close() " + mSocketType +
" socket during connection failure", e2);
}
connectionFailed();
return;
}
// Reset the ConnectThread because we're done
synchronized (BluetoothChatService.this) {
mConnectThread = null;
}
// Start the connected thread
connected(mmSocket, mmDevice, mSocketType);
}
UPDATE 1:
I've been thinking about this problem and I've commented some lines from BluetoothChatService and the connection between Samsung and Xperia devices are right now. The connection is established, but it passed by the exception code and finished the connection, so I commented the exception code. But, when I tried to connect a Xperia and a Galaxy Nexus, it has problem.
Run method in ConnectThread class is:
public void run() {
Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType);
setName("ConnectThread" + mSocketType);
// Always cancel discovery because it will slow down a connection
mAdapter.cancelDiscovery();
// Make a connection to the BluetoothSocket
try {
// This is a blocking call and will only return on a
// successful connection or an exception
mmSocket.connect();
} catch (IOException e) {
// Close the socket
// try {
// mmSocket.close();
// } catch (IOException e2) {
// Log.e(TAG, "unable to close() " + mSocketType +
// " socket during connection failure", e2);
// }
// connectionFailed();
// return;
}
// Reset the ConnectThread because we're done
synchronized (BluetoothService.this) {
mConnectThread = null;
}
// Start the connected thread
connected(mmSocket, mmDevice, mSocketType);
}