title: Android BLE BluetoothAdapter.LeScanCallback scanRecord length ambiguity
body: <p>I am using the example project from google (<a href="http://developer.android.com/samples/BluetoothLeGatt/project.html" rel="nofollow noreferrer">BluetoothLeGatt</a>) to receive data from a BLE device and trying to read a specific byte within it's scanRecord obtained by the <strong>onLeScan</strong> method. </p>
  
  <p>My problem is that there is missmatch between the data I am observing in the network and what I see on logs. </p>
  
  <p>This is on Android 4.3 and using a Samsung Galaxy S4 to test it. 
  To verify that the scanRecord logs are correct on Android, I am using TI's Packet Sniffer to observe the byte stream being broadcasted by the device, and here it is:
  <img src="https://i.stack.imgur.com/iKAYe.png" alt="enter image description here"></p>
  
  <p>That is 31 bytes of data being broadcasted by the device to the network, and there are no other working devices around.</p>
  
  <blockquote>
    <p>02 01 1A 1A FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 0C C6 64</p>
  </blockquote>
  
  <p>On the other hand, Android logs claim that the data being received has the length of 62 bytes and it matches the data until the 29th[0-indexed] byte, having 0s for the rest of the data.</p>
  
  <blockquote>
    <p>02-12 15:34:09.548: D/DEBUG(26801): len: 62
    data:02011a1aff4c000215000000000000000000000000000000000000000cc60000000000000000000000000000000000000000000000000000000000000000</p>
  </blockquote>
  
  <p>And this is the code piece I used in order to obtain the logs within the <strong>LeScanCallback</strong> method:</p>
  
  <pre><code>int len = scanRecord.length;
  String scanHex = bytesToHex(scanRecord);
  Log.d("DEBUG", "len: " + len + " data:" + scanHex);
  </code></pre>
  
  <p>The method used to convert byte array to hex representation:</p>
  
  <pre><code>private static String bytesToHex(byte[] bytes) {
          char[] hexChars = new char[bytes.length * 2];
          int v;
          for ( int j = 0; j &lt; bytes.length; j++ ) {
              v = bytes[j] &amp; 0xFF;
              hexChars[j * 2] = hexArray[v &gt;&gt;&gt; 4];
              hexChars[j * 2 + 1] = hexArray[v &amp; 0x0F];
          }
          return new String(hexChars);
      } 
  </code></pre>
  
  <p>I used a few other example projects including Dave Smith's <a href="https://thenewcircle.com/s/post/1553/bluetooth_smart_le_android_tutorial" rel="nofollow noreferrer">example</a> and RadiusNetworks' <a href="http://developer.radiusnetworks.com/ibeacon/android/" rel="nofollow noreferrer">Android iBeacon Library</a> and I ended up with the same results. I can't possibly understand why do I receive 62 bytes of data when "Packet Sniffer" shows (and I also know) that it should be 31 bytes. This would not be my main concern if I was able to read the data in the last byte correctly (I get <strong>00</strong> instead of <strong>64</strong> from Android's BluetoothAdapter). But that is not the case either. </p>
  
  <p>I would appreciate any suggestions about what might potentially be the reason for this missmatch for both the data(last byte only) and the data size between what Android receives and what is actually on the network.</p>