s.connect(); mmSocket = s; } catch (Exception ex) { Log.e(TAG, ex.toString()); mmSocket = null; try {毕业论文 connectionType = "Insecure"; Log.d(TAG, "Attempting createInsecureRfcommSocket"); BluetoothSocket s = improvedBluetoothDevice.createInsecureRfcommSocket(port); s.connect(); mmSocket = s; } catch (Exception ex2) { Log.e(TAG, ex2.toString()); mmSocket = null; } } if (mmSocket != null) { Log.d(TAG, "Connection succeeded with " + connectionType + " connection on port " + port); break; } }
//如果还没有获取到mmSocket ,就使用以下方法 if (mmSocket == null) { try { mmSocket = improvedBluetoothDevice.createRfcommSocketToServiceRecord(MY_UUID); mmSocket.connect(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // Reset the ConnectThread because we're done synchronized (BluetoothChatService.this) { mConnectThread = null; }
// Start the connected thread connected(mmSocket, mmDevice); }
public void cancel() { try { if(mmSocket!=null) { mmSocket.close();
上一页 [1] [2] [3] [4] [5] [6] 下一页
|