蓝牙打印项目里socket.connect()连接不上啊,大婶们99
private class ConnectThread extends Thread {private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
public ConnectThread(BluetoothDevice device){
Log.i(TAG, "ConnectThread");
Log.i("wang",device + "12345");
mmDevice = device;
BluetoothSocket tmp = null;
try {
//建立于蓝牙设备通道
//tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
tmp = (BluetoothSocket) (device.getClass().getMethod("createRfcommSocket",
new Class[] {int.class})).invoke(device, 1);
// tmp = device.createRfcommSocketToServiceRecord(
// MY_UUID);
} catch (Exception e) {
e.printStackTrace();
}
mmSocket = tmp;
Log.i(TAG, "mmSocket "+(mmSocket==null)+"");
}
public void run() {
// Log.i(tag, "++ConnectThread.run()++");
// mAdapter.cancelDiscovery();
try {
Log.i(TAG, "正在连接服务器");
mmSocket.connect();
Log.i(TAG, "连接服务器成功");
} catch (IOException e) {
Log.i(TAG, "连接失败信息是"+e.getMessage());
try {
mmSocket.close();
} catch (IOException e2) {
e2.printStackTrace();
}
connectionFailed();
return;
}
synchronized (BluetoothService.this) {
mConnectThread = null;
}
connected(mmSocket, mmDevice);
}
public void cancel() {
// Log.i(tag, "++ConnectThread.cancel()++");
try {
mmSocket.close();
} catch (IOException e) {
// Log.e(tag, "ConnectThread.cancel()\n" + e.getMessage());
}
}
} --------------------编程问答-------------------- 异常信息有Connection refused,Software caused connection abort,Unable to start Service Discovery,Service discovery canceled,socket closed
,他们轮着来,头疼啊 --------------------编程问答-------------------- MY_UUID="00001101-0000-1000-8000-00805F9B34FB"
补充:移动开发 , Android