title: How to browse a File and Send it via Bluetooth to the connected device?
body: <p><strong>Obs: I know that here have many questions about this, but none of them do what i want, seriously, so don't downvote it due to <code>Duplicate</code> question, thanks.</strong></p>
  
  <p>Well, i have a application that have all the necessary <code>Bluetooth</code> classes for connection and managing and etc. My application is a <code>Chat</code> via <code>Bluetooth</code>, i can send string messages to another device and the other device can send to me too. <code>Server</code> and <code>Client</code>.</p>
  
  <p>Here is my method to send <code>Message</code> (working)</p>
  
  <pre><code>public boolean sendMessageByBluetooth(String msg){
      try {
          if(dataOutputStream != null){
              dataOutputStream.write(msg.getBytes());
              dataOutputStream.flush();
              return true;
          }else{
              sendHandler(ChatActivity.MSG_TOAST, context.getString(R.string.no_connection));
              return false;
          }
      } catch (IOException e) {
          LogUtil.e(e.getMessage());
  
          sendHandler(ChatActivity.MSG_TOAST, context.getString(R.string.failed_to_send_message));
          return false;
      }
  }
  </code></pre>
  
  <p>I want, if possible, a method that is similar to that method, that can <code>Send Files</code> so i can use the same source to implement the <code>File Transfer</code>.</p>
  
  <p>But i need to have a functionality on my app that is a <code>File Transfer</code>, that have a <code>Browse</code> button to search a file on your <code>Device</code> and then select it and send to paired device, simple as that.</p>
  
  <p>Too, i want to see a <code>ProgressBar</code> filling to the user see how long it will take to send the file :)</p>
  
  <p>How i can do that?</p>
  
  <p><strong>--EDIT--</strong></p>
  
  <p>I am trying the <code>File Transfer</code> here is what i did:</p>
  
  <p><code>FileActivity.java</code></p>
  
  <p>onCreate event to connect:</p>
  
  <pre><code>verifyAndActivateBluetooth(); //this function is same used on ChatActivity it is working.
  registerFilter(); //this function is same used on ChatActivity it is working.
  chatBusinessLogic.startFoundDevices(); //this function is same used on ChatActivity and it is working.
  </code></pre>
  
  <p>Then i choose the visible another device and it connect successful.</p>
  
  <p>After connected Then..</p>
  
  <p>Button <code>Browse</code> -> Intent to show the file explorer:</p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  intent.setType("file/*");
  startActivityForResult(intent, FILE_FOUND); 
  </code></pre>
  
  <p>FileActivity onActivityResult <code>switch(requestCode)</code>:</p>
  
  <pre><code>case FILE_FOUND:
      filename = data.getData().getPath(); //here was the problem of error 1. now fixed
      if(filename.trim().length() &gt; 0){
  
          if(chatBusinessLogic.sendFile(filename)){
              lblFilename.setText(filename);
              toastUtil.showToast("Success");
          }
      }else{
          toastUtil.showToast("fail");
      }
  </code></pre>
  
  <p>The <code>chatBusinessLogic.sendFile(filename)</code> :</p>
  
  <pre><code>public boolean sendFile(String file){
  
      if(bluetoothComunication != null){
          return bluetoothComunication.sendFileByBluetooth(file);
      }else{
          return false;
      }
  }   
  </code></pre>
  
  <p>the <code>bluetoothComunication.sendFileByBluetooth(file)</code>:</p>
  
  <p>public boolean sendFileByBluetooth(String fpath){</p>
  
  <pre><code>File f = new File(fpath);
  int n  = 0;
  byte b[] = new byte[(int) f.length()];
  try
  {
      FileInputStream fileInputStream = new FileInputStream(new File(fpath)); //ERROR FIXED
      DataOutputStream dataOut = new DataOutputStream(dataOutputStream);
      while (-1 != (n = fileInputStream.read(b))){
          dataOutputStream.write(b, 0, n);
      }
      dataOut.flush();
      fileInputStream.close();
      dataOut.close();
      return true;
  }catch(IOException e)
  {
      LogUtil.e("Error converting file");
      LogUtil.e(e.getMessage());
      return false;
  }
  </code></pre>
  
  <p>i was getting this error(<strong>NOW IT IS FIXED</strong>):
  If i choose android native method for physical path:</p>
  
  <pre><code>/content:/com.estrongs.files/mnt/sdcard/calc-history.txt: open failed: ENOENT (No such file or directory)
  </code></pre>
  
  <p>If i choose alternative method for physical path:</p>
  
  <pre><code>/file:/mnt/sdcard/calc-history.txt: open failed: ENOENT (No such file or directory)
  </code></pre>
  
  <p>The error above was fixed using <code>filename = data.getData().getPath();</code> on the case <code>FILE_FOUND</code> instead of <code>filename = data.getDataString();</code></p>
  
  <p>Now i have another error on this line:</p>
  
  <pre><code>dataOutputStream.write(b, 0, n);
  </code></pre>
  
  <p>The error message is that: <code>Transport endpoint is not connected</code>, what i should do?</p>