Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid java.io.IOException: Transport endpoint is not connected
    text
    copied!<p>I need to send a string to a bluetooth device. But while sending,I am getting an Exeption <code>java.io.IOException: Transport endpoint is not connected</code> on <code>java.io.OutputStream.write(byte[])</code> method.</p> <p>The Code Is as shown below. The code just search a specific device from the paired device list and send string.</p> <pre><code>public class MainActivity extends Activity { TextView out; private static final int REQUEST_ENABLE_BT = 1; private BluetoothAdapter btAdapter; private ArrayList&lt;BluetoothDevice&gt; btDeviceList = new ArrayList&lt;BluetoothDevice&gt;(); private ArrayAdapter&lt;String&gt; mPairedDevicesArrayAdapter; private ArrayAdapter&lt;String&gt; mNewDevicesArrayAdapter; BluetoothDevice device1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); out = (TextView) findViewById(R.id.out); btAdapter = BluetoothAdapter.getDefaultAdapter(); ListpairedDevices(); } /* This routine is called when an activity completes. */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_ENABLE_BT) { CheckBTState(); } } public void ListpairedDevices() { Set&lt;BluetoothDevice&gt; pairedDevices = btAdapter.getBondedDevices(); // If there are paired devices, add each one to the ArrayAdapter if (pairedDevices.size() &gt; 0) { out.append("\nPaired Devices \n"); for (BluetoothDevice device : pairedDevices) { out.append("\n Device123: " + device.getName() + "," + device); //mPairedDevicesArrayAdapter.add("\n Device123: " + device.getName() + "," + device); String dv=device.toString(); if(dv.contains("00:1B:EE:82:31:1E")) { device1=device; } } } else { out.append("\nNo Pared Device"); } out.append("\nDiscovered Devices"); } public void sendtext(View v) {//button click Set&lt;BluetoothDevice&gt; bd=btAdapter.getBondedDevices(); sendDataToPairedDevice("message1"); } private void sendDataToPairedDevice(String message ){ byte[] toSend = message.getBytes(); try { UUID applicationUUID = UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66"); BluetoothSocket socket = device1.createInsecureRfcommSocketToServiceRecord(applicationUUID); OutputStream mmOutStream = socket.getOutputStream(); mmOutStream.write(toSend); } catch (IOException e) { Log.e( "Exception during write", e.toString()); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload