title: android - bluetooth adapter - message handler buffer limit
body: <p>I'm using this tutorial for building a multiplayer game that uses Bluetooth for connection:</p>
  
  <p><a href="https://developer.android.com/samples/BluetoothChat/index.html" rel="nofollow">https://developer.android.com/samples/BluetoothChat/index.html</a></p>
  
  <p>Since I'm sending long stings in JSON format (like 5500+ in length) the message handler method is not returning the entire strings I send, and instead it splits them into 989 character long strings (its always 989 characters in length). The problem is, when I try to parse the JSON string, obviously it throws an error, because the text is not complete. When I print out the string in console, it prints them in multiple rows split by 989 characters.</p>
  
  <p>Also please note that the Buffer length is set to 1024, but when I increase the limit, the result won't differ, and its always 989 characters.</p>
  
  <pre><code>byte[] buffer = new byte[1024];
  </code></pre>
  
  <p>Any idea what's going on? Here's the message handler method. Note that the sent message form the host device looks fine (its not split), but when the client receives it, its split into multiple strings.</p>
  
  <pre><code>private static final Handler mHandler = new Handler() {
      @Override
      public void handleMessage(Message msg) {
          switch (msg.what) {
              case BluetoothService.MESSAGE_STATE_CHANGE:
                  switch (msg.arg1) {
                      case BluetoothService.STATE_CONNECTED:
                      case BluetoothService.STATE_CONNECTING:
                      case BluetoothService.STATE_LISTEN:
                      case BluetoothService.STATE_NONE:
                          break;
                  }
                  break;
              case BluetoothService.MESSAGE_WRITE:
                  // BYTE LENGTH IS OK IN HERE!
                  byte[] writeBuf = (byte[]) msg.obj;
                  String writeMessage = new String(writeBuf);
                  break;
              case BluetoothService.MESSAGE_READ:
                  // BYTE LENGTH IS 1024 IN HERE!
                  byte[] readBuf = (byte[]) msg.obj;
                  message = new String(readBuf, 0, msg.arg1);
                  break;
          }
      }
  };
  </code></pre>