How to prevent Android bluetooth RFCOMM connection from dying immediately after .connect()?

Try to change your code for creating RfcommSocket:

sock = zee.createRfcommSocketToServiceRecord(
                      UUID.fromString("8e1f0cf7-508f-4875-b62c-fbb67fd34812"));

for this code:

Method m = zee.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
sock = (BluetoothSocket) m.invoke(device, 1);

Also try to change argument value in range 1-3 in this m.invoke(device, 1);
When connection will be Connected, but aborted when you try reading, call in some loop your method test() again.
As simple:

for(int i=0;i<3;i++){  if(!testDone) test(); }

Leave a Comment