public void run() { BluetoothSocket socket = null; while (mState != co.lujun.lmbluetoothsdk.base.State.STATE_CONNECTED) { try { socket = mmServerSocket.accept(); } catch (IOException e) { break; } if (socket != null) { synchronized (BluetoothService.this) { switch (mState) { case co.lujun.lmbluetoothsdk.base.State.STATE_LISTEN: case co.lujun.lmbluetoothsdk.base.State.STATE_CONNECTING: case co.lujun.lmbluetoothsdk.base.State.STATE_DISCONNECTED: connected(socket); break; case co.lujun.lmbluetoothsdk.base.State.STATE_NONE: case co.lujun.lmbluetoothsdk.base.State.STATE_CONNECTED: try { socket.close(); } catch (IOException e) {} break; } } } } }
public void run() { mAdapter.cancelDiscovery(); try { mmSocket.connect(); } catch (IOException e) { setState(co.lujun.lmbluetoothsdk.base.State.STATE_LISTEN); try { mmSocket.close(); } catch (IOException e2) {} BluetoothService.this.start(); return; } synchronized (BluetoothService.this) { mConnectThread = null; } connected(mmSocket); }