我想连接一个蓝牙设备与我的Android应用程序。到目前为止它的工作正常。服务发现失败重新连接蓝牙设备
现在的问题是当我的设备超出范围,我显示一个对话框并要求用户重新连接或不。
有时我能够用设备重新连接,有时我得到的错误,即
Service Discovery Failed
,我真的不知道为什么它的发生
private class ConnectThread extends Thread {
public ConnectThread() {
try {
bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(UUID);
} catch (IOException e) {
System.out.println("IO EXCEPTION" + e.getMessage() +"");
}
}
public void run() {
bluetoothAdapter.cancelDiscovery();
try {
// I AM GETTING ERROR HERE
bluetoothSocket.connect();
} catch (IOException connectException) {
Log.d("Exception : ConnectThread -> Run" , connectException.getMessage()+"");
try {
bluetoothSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
}
}