80,351
社区成员
发帖
与我相关
我的任务
分享
try{mmSocket.connect();}
这段代码没有运行,请大神指点是什么原因。public ConnectThread(BluetoothDevice device) {
// Use a temporary object that is later assigned to mmSocket,
// because mmSocket is final
BluetoothSocket tmp = null;
mmDevice = device;
// Get a BluetoothSocket to connect with the given BluetoothDevice
try {
// MY_UUID is the app's UUID string, also used by the server code
tmp = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
//mmSocket = tmp;
System.out.println("--->1");
} catch (IOException e) { }
mmSocket = tmp;
System.out.println("--->>2");
// return;
}
public void run() {
// Cancel discovery because it will slow down the connection
mBluetoothAdapter.cancelDiscovery();
System.out.println("--->>>3");
try {
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
mmSocket.connect();
System.out.println("--->>>>4");
} catch (IOException connectException) {
// Unable to connect; close the socket and get out
try {
mmSocket.close();
System.out.println("--->>>>>5");
} catch (IOException closeException) { }
return;
}
// Do work to manage the connection (in a separate thread)
//manageConnectedSocket(mmSocket);
}
/** Will cancel an in-progress connection, and close the socket */
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) { }
}
}