扫描通过广播得到我要的已经配对过的蓝牙设备之后进行连接,一直报E/TAG: java.io.IOException: read failed, socket might closed or timeout, read ret: -1代码如下
if(addr.equals("74:23:44:CF:4E:DF")){
device.fetchUuidsWithSdp();
mBluetoothAdapter.cancelDiscovery();
if(device.getBondState() == BluetoothDevice.BOND_BONDED){
device = mBluetoothAdapter.getRemoteDevice("74:23:44:CF:4E:DF");
new Thread(new Runnable() {
@Override
public void run() {
BluetoothSocket tmp = null;
Method method;
try {
method = device.getClass().getMethod("createRfcommSocket", new Class[]{int.class});
tmp = (BluetoothSocket) method.invoke(device, 1);
} catch (Exception e) {
Log.e("TAG", e.toString());
}
socket = tmp;
try {
socket.connect();
} catch (Exception e) {
Log.e("TAG", e.toString());
}
}
}).start();
求诸位大神指点。