googlearchive/android-BluetoothChat

Socket not connecting

vishal-raj opened this issue · 2 comments

Always getting exception:

W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
com.example.android.bluetoothchat W/System.err:     at   android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:745)
com.example.android.bluetoothchat W/System.err:     at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:757)
com.example.android.bluetoothchat W/System.err:     at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:379)
4rz0 commented

@vishal-raj
How was this resolved?

Using reflection method:

Method m;
try {
m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class });
tmp = (BluetoothSocket) m.invoke(device, 1);
} catch (SecurityException e) {
Log.e(TAG, "create() failed", e);
} catch (NoSuchMethodException e) {
Log.e(TAG, "create() failed", e);
} catch (IllegalArgumentException e) {
Log.e(TAG, "create() failed", e);
} catch (IllegalAccessException e) {
Log.e(TAG, "create() failed", e);
} catch (InvocationTargetException e) {
Log.e(TAG, "create() failed", e);
}

mmSocket = tmp;
}