title: Reading value of characteristic after connecting to service Bluetooth Low Energy Android
body: <p>after the connection is established I want to read the value from the characteristic and save the value in a byte array.</p>
  
  <p>Here is my function for the reading inside my BluetoothLeService:</p>
  
  <pre><code>  public byte[] readWhiteAndIntensityCharacteristic() {
  if (mBluetoothAdapter == null || mBluetoothGatt == null) {
      Log.w(TAG, "BluetoothAdapter not initialized");
      return null;
  }
  /*check if the service is available on the device*/
  BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString(UuidAdresssService));
  if (mCustomService == null) {
      Log.w(TAG, "Custom BLE Service not found");
      return null;
  }
  /*get the read characteristic from the service*/
  BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(UUID.fromString(UuidAdresssWhiteAndIntensityCharastic));
  byte[] messageByte = mReadCharacteristic.getValue();
  if (messageByte != null &amp;&amp; messageByte.length &gt; 0) {
      final StringBuilder stringBuilder = new StringBuilder(messageByte.length);
      for (byte byteChar : messageByte)
          stringBuilder.append(String.format("%02X", byteChar));
      s = "0x" + stringBuilder.toString();
      Log.v("Scan Activity", s);
      if (mBluetoothGatt.readCharacteristic(mReadCharacteristic) == false) {
          Log.w(TAG, "Failed to read characteristic");
      }
  }
  return messageByte;
  </code></pre>
  
  <p>}
  This function get called inside my DeviceControlActivity:</p>
  
  <pre><code>    public void getStartUpValue(){
      Log.w(TAG, "Reading completed");}
    if(mBluetoothLeService.readWhiteAndIntensityCharacteristic() == null)
    {
        Log.w(TAG, "FAILED Reading value failed");
    }
      startValue = mBluetoothLeService.readWhiteAndIntensityCharacteristic();
      Log.w(TAG, "Reading completed");
  
  }
  </code></pre>
  
  <p>I call the getStartUpValue function after the connection is established.</p>
  
  <pre><code>  private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
      final String action = intent.getAction();
      if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
          mConnected = true;
          updateConnectionState(R.string.connected);
          invalidateOptionsMenu();
      } else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
          mConnected = false;
          updateConnectionState(R.string.disconnected);
          invalidateOptionsMenu();
          clearUI();
      } else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
          // Show all the supported services and characteristics on the user interface.
          mBluetoothLeService.getSupportedGattServices();
          getStartUpValue();
  
      } else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
          displayData(intent.getStringExtra(BluetoothLeService.EXTRA_DATA));
  
      }
  }
  </code></pre>
  
  <p>};</p>
  
  <p>The reading is failing everytime but sending values to the characteristic is no problem.</p>
  
  <p>How can I fix this problem?</p>