Android BLE characteristics getValue returns null
<p>I am trying to write text data to my BLE device. So , i am following Android Bluetooth GATT classes to do the task. But i found writing the text to the Characteristics is fine but while trying to retrieve the Characteristics value , it returns null.</p>

<p>MyCode :</p>

<pre><code>public void writeCharacteristic(BluetoothGattCharacteristic characteristic,
                                String text) {

    String TAGS ="MyBeacon";

    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAGS, "BluetoothAdapter not initialized");
        return;
    } else {
        Log.w(TAGS, "Writting ... ");
    }
    byte[] data = hexStringToByteArray(text);


    Log.w(TAGS, "Writting text = " + data);


    try {
        characteristic.setValue(URLEncoder.encode(text, "utf-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    boolean writeValue = mBluetoothGatt.writeCharacteristic(characteristic);

    Log.w(TAGS, "Writting Status = " + writeValue);

}
</code></pre>

<p>// Successfully onCharacteristicWrite also gets called //</p>

<pre><code>   @Override
    public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
        super.onCharacteristicWrite(gatt, characteristic, status);

        String TAGS ="MyBeacon";

        String text = null;
        try {
            text = new String(characteristic.getValue(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        Log.w(TAGS, "onCharacteristicWrite = " + text+" :: "+status);

    }
</code></pre>

<p>but while trying to read the Characteristics it returns null.</p>

<pre><code>  for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {

                final byte[] data = gattCharacteristic.getValue(); // returns null

                  if (data != null &amp;&amp; data.length &gt; 0) {

                     Log.d("MyBeacon", " Read Data ")

                  } else {

                     Log.d("MyBeacon", " Data is null")
                  }

      }
</code></pre>

<p><a href="http://www.amazon.in/gp/product/B019U6O0IM?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o00_s00" rel="noreferrer">MyBeacon</a></p>

<p><a href="https://stackoverflow.com/questions/35937529/how-to-transfer-data-between-two-android-devices-using-beacon">Also check the issue in other thread too.</a></p>

<p>Please help me out , suggest me some solution to write and read data successfully to my Beacon.</p>