If you are sure that the connection is established without any errors and you can get the socket, try assigning your OutputStream member in the run() method as follows:
public void run() { mBluetoothAdapter.cancelDiscovery(); try { btSocket = device.createRfcommSocketToServiceRecord(MY_UUID); } catch (IOException e) { Log.e(TAG, "ON START: Socket creation failed.", e); } try { btSocket.connect(); } catch (IOException e) { Log.e(TAG, "sendTestByte: Socket connection failed.", e); } try { outStream = btSocket.getOutputStream(); } catch (IOException e) { Log.e(TAG, "sendTestByte: OutputStream creation failed.", e); } } public void sendTestString(String s) { try { outStream.write(s.getBytes()); outSttream.flush();
You are not actually closing the socket, but this should work. Make sure that the connection to the master is not lost before calling write()
source share