title: Bluetooth connection in Android studio
body: <p>I am trying to develop two apps on android studio, each to run on different Android device. I want to exchange data between those two using Bluetooth. I have followed the Android Developer documentation and I did the following: search for devices, establish the RFCOMM channel, connected both devices. However, I cannot see the data sent or received. One app is a client to initiate the connection, the other app is both client and server side. Once connected I am using Handler to write/read from the stream. Here is the handler code. For the <code>connectedThread</code> and <code>ConnectThread</code>, I have used the same as in the Android Developer example. However, I am not sure when to call both <code>read()</code> and <code>write()</code> methods and where usually messages exchanged between the two connected devices are stored? </p>
  
  <pre><code>Handler mhandler = new Handler(){
          @Override
          public void handleMessage(Message msg){
              super.handleMessage(msg);
              Log.i(tag, "in handler");
              String s = myapplication.getMessage();
              ConnectedThread connectedThread = new ConnectedThread((BluetoothSocket)msg.obj);
              connectedThread.run();
              switch (msg.what){
                  case SUCCESS_CONNECT:
                      //ConnectedThread connectedThread = new ConnectedThread((BluetoothSocket)msg.obj);
                      Toast.makeText(getApplicationContext(), "CONNECT", Toast.LENGTH_LONG).show();
                      break;
                  case MESSAGE_WRITE:
                      connectedThread.write(s.getBytes());
                      break;
                  case MESSAGE_READ:
                      byte[] readbuf = (byte[])msg.obj;
                      String string = new String(readbuf);
                      Toast.makeText(getApplicationContext(), string, Toast.LENGTH_LONG).show();
                      break;
              }
          }
      };
  </code></pre>