@Override
 protected void onDestroy() {
   super.onDestroy();
   if (mBle != null) {
     mBle.disconnect(mDeviceAddress);
   }
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.menu_connect:
       mBle.requestConnect(mDeviceAddress);
       return true;
     case R.id.menu_disconnect:
       mBle.disconnect(mDeviceAddress);
       onDeviceDisconnected();
       return true;
     case android.R.id.home:
       onBackPressed();
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
 @Override
 protected void onResume() {
   super.onResume();
   registerReceiver(mBleReceiver, BleService.getIntentFilter());
   ArrayList<BleGattService> services = mBle.getServices(mDeviceAddress);
   if (services == null || services.size() == 0) {
     onDeviceDisconnected();
   }
 }
 @Override
 public boolean onChildClick(
     ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
   Log.d(TAG, "onChildClick " + groupPosition + " " + childPosition);
   if (mGattCharacteristics != null) {
     final BleGattCharacteristic characteristic =
         mGattCharacteristics.get(groupPosition).get(childPosition);
     Intent intent = new Intent(DeviceControlActivity.this, CharacteristicActivity.class);
     intent.putExtra("address", mDeviceAddress);
     Log.d(TAG, "service size " + mBle.getServices(mDeviceAddress).size());
     intent.putExtra(
         "service",
         mBle.getServices(mDeviceAddress).get(groupPosition).getUuid().toString());
     intent.putExtra("characteristic", characteristic.getUuid().toString().toUpperCase());
     startActivity(intent);
     return true;
   }
   return false;
 }
        @Override
        public void onReceive(Context context, Intent intent) {
          Bundle extras = intent.getExtras();
          if (!mDeviceAddress.equals(extras.getString(BleService.EXTRA_ADDR))) {
            return;
          }

          String action = intent.getAction();
          if (BleService.BLE_GATT_CONNECTED.equals(action)) {
            mConnected = true;
            updateConnectionState(R.string.connected);
            invalidateOptionsMenu();
          } else if (BleService.BLE_GATT_DISCONNECTED.equals(action)) {
            onDeviceDisconnected();
          } else if (BleService.BLE_SERVICE_DISCOVERED.equals(action)) {
            displayGattServices(mBle.getServices(mDeviceAddress));
          }
        }