Android Mail Information To Bluetooth Le Device, Using Hm-10 Ble Module

Posted on

The previous postal service present how to “Modified BluetoothLeGatt sample for HM-10 (Bluetooth LE Module)“, to have data. In the master illustration code haven’t grip shipping information from Android to Bluetooth LE device. It’s modified to echo the received information dorsum HM-10, to sender.


Modify BluetoothLeService.java to add together method writeCharacteristic(BluetoothGattCharacteristic characteristic) to write data.

/*  * Copyright (C) 2013 The Android Open Source Project  *  * Licensed nether the Apache License, Version 2.0 (the "License");  * you lot may non role this file except inwards compliance amongst the License.  * You may obtain a re-create of the License at  *  *      http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required past times applicable constabulary or agreed to inwards writing, software  * distributed nether the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either limited or implied.  * See the License for the specific linguistic communication governing permissions too  * limitations nether the License.  */  packet com.example.android.bluetoothlegatt;  import android.app.Service; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCallback; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.Intent; import android.os.Binder; import android.os.IBinder; import android.util.Log;  import java.util.List; import java.util.UUID;  /**  * Service for managing connexion too information communication amongst a GATT server hosted on a  * given Bluetooth LE device.  */ populace storey BluetoothLeService extends Service {     mortal lastly static String TAG = BluetoothLeService.class.getSimpleName();      mortal BluetoothManager mBluetoothManager;     mortal BluetoothAdapter mBluetoothAdapter;     mortal String mBluetoothDeviceAddress;     mortal BluetoothGatt mBluetoothGatt;     mortal int mConnectionState = STATE_DISCONNECTED;      mortal static lastly int STATE_DISCONNECTED = 0;     mortal static lastly int STATE_CONNECTING = 1;     mortal static lastly int STATE_CONNECTED = 2;      populace lastly static String ACTION_GATT_CONNECTED =             "com.example.bluetooth.le.ACTION_GATT_CONNECTED";     populace lastly static String ACTION_GATT_DISCONNECTED =             "com.example.bluetooth.le.ACTION_GATT_DISCONNECTED";     populace lastly static String ACTION_GATT_SERVICES_DISCOVERED =             "com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED";     populace lastly static String ACTION_DATA_AVAILABLE =             "com.example.bluetooth.le.ACTION_DATA_AVAILABLE";     populace lastly static String EXTRA_DATA =             "com.example.bluetooth.le.EXTRA_DATA";      populace lastly static UUID UUID_HEART_RATE_MEASUREMENT =             UUID.fromString(SampleGattAttributes.HM_10);      // Implements callback methods for GATT events that the app cares about.  For example,     // connexion alter too services discovered.     mortal lastly BluetoothGattCallback mGattCallback = novel BluetoothGattCallback() {         @Override         populace void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {             String intentAction;             if (newState == BluetoothProfile.STATE_CONNECTED) {                 intentAction = ACTION_GATT_CONNECTED;                 mConnectionState = STATE_CONNECTED;                 broadcastUpdate(intentAction);                 Log.i(TAG, "Connected to GATT server.");                 // Attempts to regain services after successful connection.                 Log.i(TAG, "Attempting to start service discovery:" +                         mBluetoothGatt.discoverServices());              } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {                 intentAction = ACTION_GATT_DISCONNECTED;                 mConnectionState = STATE_DISCONNECTED;                 Log.i(TAG, "Disconnected from GATT server.");                 broadcastUpdate(intentAction);             }         }          @Override         populace void onServicesDiscovered(BluetoothGatt gatt, int status) {             if (status == BluetoothGatt.GATT_SUCCESS) {                 broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);             } else {                 Log.w(TAG, "onServicesDiscovered received: " + status);             }         }          @Override         populace void onCharacteristicRead(BluetoothGatt gatt,                                          BluetoothGattCharacteristic characteristic,                                          int status) {             if (status == BluetoothGatt.GATT_SUCCESS) {                 broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);             }         }          @Override         populace void onCharacteristicChanged(BluetoothGatt gatt,                                             BluetoothGattCharacteristic characteristic) {             broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);         }     };      mortal void broadcastUpdate(final String action) {         lastly Intent intent = novel Intent(action);         sendBroadcast(intent);     }      mortal void broadcastUpdate(final String action,                                  lastly BluetoothGattCharacteristic characteristic) {         lastly Intent intent = novel Intent(action);          /*         // This is particular treatment for the Heart Rate Measurement profile.  Data parsing is         // carried out every bit per profile specifications:         // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml         if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {             int flag = characteristic.getProperties();             int format = -1;             if ((flag & 0x01) != 0) {                 format = BluetoothGattCharacteristic.FORMAT_UINT16;                 Log.d(TAG, "Heart charge per unit of measurement format UINT16.");             } else {                 format = BluetoothGattCharacteristic.FORMAT_UINT8;                 Log.d(TAG, "Heart charge per unit of measurement format UINT8.");             }             lastly int heartRate = characteristic.getIntValue(format, 1);             Log.d(TAG, String.format("Received view rate: %d", heartRate));             intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));         } else {             // For all other profiles, writes the information formatted inwards HEX.             lastly byte[] information = characteristic.getValue();             if (data != nothing && data.length > 0) {                 lastly StringBuilder stringBuilder = novel StringBuilder(data.length);                 for(byte byteChar : data)                     stringBuilder.append(String.format("%02X ", byteChar));                 intent.putExtra(EXTRA_DATA, novel String(data) + "\n" + stringBuilder.toString());             }         }         */          Log.w(TAG, "broadcastUpdate()");          lastly byte[] information = characteristic.getValue();          Log.v(TAG, "data.length: " + data.length);          if (data != nothing && data.length > 0) {             lastly StringBuilder stringBuilder = novel StringBuilder(data.length);             for(byte byteChar : data) {                 stringBuilder.append(String.format("%02X ", byteChar));                  Log.v(TAG, String.format("%02X ", byteChar));             }             intent.putExtra(EXTRA_DATA, novel String(data) + "\n" + stringBuilder.toString());         }          sendBroadcast(intent);     }      populace storey LocalBinder extends Binder {         BluetoothLeService getService() {             render BluetoothLeService.this;         }     }      @Override     populace IBinder onBind(Intent intent) {         render mBinder;     }      @Override     populace boolean onUnbind(Intent intent) {         // After using a given device, you lot should brand certain that BluetoothGatt.close() is called         // such that resources are cleaned upwards properly.  In this item example, close() is         // invoked when the UI is disconnected from the Service.         close();         render super.onUnbind(intent);     }      mortal lastly IBinder mBinder = novel LocalBinder();      /**      * Initializes a reference to the local Bluetooth adapter.      *      * @return Return truthful if the initialization is successful.      */     populace boolean initialize() {         // For API storey eighteen too above, larn a reference to BluetoothAdapter through         // BluetoothManager.         if (mBluetoothManager == null) {             mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);             if (mBluetoothManager == null) {                 Log.e(TAG, "Unable to initialize BluetoothManager.");                 render false;             }         }          mBluetoothAdapter = mBluetoothManager.getAdapter();         if (mBluetoothAdapter == null) {             Log.e(TAG, "Unable to obtain a BluetoothAdapter.");             render false;         }          render true;     }      /**      * Connects to the GATT server hosted on the Bluetooth LE device.      *      * @param address The device address of the destination device.      *      * @return Return truthful if the connexion is initiated successfully. The connexion outcome      *         is reported asynchronously through the      *         {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)}      *         callback.      */     populace boolean connect(final String address) {         if (mBluetoothAdapter == nothing || address == null) {             Log.w(TAG, "BluetoothAdapter non initialized or unspecified address.");             render false;         }          // Previously connected device.  Try to reconnect.         if (mBluetoothDeviceAddress != nothing && address.equals(mBluetoothDeviceAddress)                 && mBluetoothGatt != null) {             Log.d(TAG, "Trying to role an existing mBluetoothGatt for connection.");             if (mBluetoothGatt.connect()) {                 mConnectionState = STATE_CONNECTING;                 render true;             } else {                 render false;             }         }          lastly BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);         if (device == null) {             Log.w(TAG, "Device non found.  Unable to connect.");             render false;         }         // We desire to straight connect to the device, too thence nosotros are setting the autoConnect         // parameter to false.         mBluetoothGatt = device.connectGatt(this, false, mGattCallback);         Log.d(TAG, "Trying to create a novel connection.");         mBluetoothDeviceAddress = address;         mConnectionState = STATE_CONNECTING;         render true;     }      /**      * Disconnects an existing connexion or cancel a pending connection. The disconnection outcome      * is reported asynchronously through the      * {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)}      * callback.      */     populace void disconnect() {         if (mBluetoothAdapter == nothing || mBluetoothGatt == null) {             Log.w(TAG, "BluetoothAdapter non initialized");             return;         }         mBluetoothGatt.disconnect();     }      /**      * After using a given BLE device, the app must telephone phone this method to ensure resources are      * released properly.      */     populace void close() {         if (mBluetoothGatt == null) {             return;         }         mBluetoothGatt.close();         mBluetoothGatt = null;     }      /**      * Request a read on a given {@code BluetoothGattCharacteristic}. The read outcome is reported      * asynchronously through the {@code BluetoothGattCallback#onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int)}      * callback.      *      * @param characteristic The characteristic to read from.      */     populace void readCharacteristic(BluetoothGattCharacteristic characteristic) {         if (mBluetoothAdapter == nothing || mBluetoothGatt == null) {             Log.w(TAG, "BluetoothAdapter non initialized");             return;         }         mBluetoothGatt.readCharacteristic(characteristic);     }      /**      * Enables or disables notification on a give characteristic.      *      * @param characteristic Characteristic to human activity on.      * @param enabled If true, enable notification.  False otherwise.      */     populace void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,                                               boolean enabled) {         if (mBluetoothAdapter == nothing || mBluetoothGatt == null) {             Log.w(TAG, "BluetoothAdapter non initialized");             return;         }         mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);          // This is specific to Heart Rate Measurement.         if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {             BluetoothGattDescriptor descriptor = characteristic.getDescriptor(                     UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));             descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);             mBluetoothGatt.writeDescriptor(descriptor);         }     }      /**      * Retrieves a listing of supported GATT services on the connected device. This should live      * invoked exclusively after {@code BluetoothGatt#discoverServices()} completes successfully.      *      * @return H5N1 {@code List} of supported services.      */     populace List<BluetoothGattService> getSupportedGattServices() {         if (mBluetoothGatt == null) render null;          render mBluetoothGatt.getServices();     }      public void writeCharacteristic(BluetoothGattCharacteristic characteristic) {         mBluetoothGatt.writeCharacteristic(characteristic);     } }  

DeviceControlActivity.java
– Add bluetoothGattCharacteristicHM_10 to proceed rail of BluetoothGattCharacteristic object of HM-10.
– Echo dorsum information to bluetoothGattCharacteristicHM_10 in BroadcastReceiver.

/*  * Copyright (C) 2013 The Android Open Source Project  *  * Licensed nether the Apache License, Version 2.0 (the "License");  * you lot may non role this file except inwards compliance amongst the License.  * You may obtain a re-create of the License at  *  *      http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required past times applicable constabulary or agreed to inwards writing, software  * distributed nether the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either limited or implied.  * See the License for the specific linguistic communication governing permissions too  * limitations nether the License.  */  packet com.example.android.bluetoothlegatt;  import android.app.Activity; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattService; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ExpandableListView; import android.widget.SimpleExpandableListAdapter; import android.widget.TextView;  import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.UUID;  /**  * For a given BLE device, this Activity provides the user interface to connect, display data,  * too display GATT services too characteristics supported past times the device.  The Activity  * communicates amongst {@code BluetoothLeService}, which inwards plow interacts amongst the  * Bluetooth LE API.  */ populace storey DeviceControlActivity extends Activity {     mortal lastly static String TAG = DeviceControlActivity.class.getSimpleName();      populace static lastly String EXTRAS_DEVICE_NAME = "DEVICE_NAME";     populace static lastly String EXTRAS_DEVICE_ADDRESS = "DEVICE_ADDRESS";      mortal TextView mConnectionState;     mortal TextView mDataField;     mortal String mDeviceName;     mortal String mDeviceAddress;     mortal ExpandableListView mGattServicesList;     mortal BluetoothLeService mBluetoothLeService;     mortal ArrayList<ArrayList<BluetoothGattCharacteristic>> mGattCharacteristics =             novel ArrayList<ArrayList<BluetoothGattCharacteristic>>();     mortal boolean mConnected = false;     mortal BluetoothGattCharacteristic mNotifyCharacteristic;      mortal lastly String LIST_NAME = "NAME";     mortal lastly String LIST_UUID = "UUID";      private BluetoothGattCharacteristic bluetoothGattCharacteristicHM_10;      // Code to create practise Service lifecycle.     mortal lastly ServiceConnection mServiceConnection = novel ServiceConnection() {          @Override         populace void onServiceConnected(ComponentName componentName, IBinder service) {             mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();             if (!mBluetoothLeService.initialize()) {                 Log.e(TAG, "Unable to initialize Bluetooth");                 finish();             }             // Automatically connects to the device upon successful start-up initialization.             mBluetoothLeService.connect(mDeviceAddress);         }          @Override         populace void onServiceDisconnected(ComponentName componentName) {             mBluetoothLeService = null;         }     };      // Handles diverse events fired past times the Service.     // ACTION_GATT_CONNECTED: connected to a GATT server.     // ACTION_GATT_DISCONNECTED: disconnected from a GATT server.     // ACTION_GATT_SERVICES_DISCOVERED: discovered GATT services.     // ACTION_DATA_AVAILABLE: received information from the device.  This tin john live a outcome of read     //                        or notification operations.     mortal lastly BroadcastReceiver mGattUpdateReceiver = novel BroadcastReceiver() {         @Override         populace void onReceive(Context context, Intent intent) {             lastly String activeness = 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 too characteristics on the user interface.                 displayGattServices(mBluetoothLeService.getSupportedGattServices());             } else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {                 displayData(intent.getStringExtra(BluetoothLeService.EXTRA_DATA));                  //Echo dorsum received data, amongst something inserted                 lastly byte[] rxBytes = bluetoothGattCharacteristicHM_10.getValue();                 lastly byte[] insertSomething = {(byte)'\n'};                 byte[] txBytes = novel byte[insertSomething.length + rxBytes.length];                 System.arraycopy(insertSomething, 0, txBytes, 0, insertSomething.length);                 System.arraycopy(rxBytes, 0, txBytes, insertSomething.length, rxBytes.length);                  if(bluetoothGattCharacteristicHM_10 != null){                     bluetoothGattCharacteristicHM_10.setValue(txBytes);                     mBluetoothLeService.writeCharacteristic(bluetoothGattCharacteristicHM_10);                     mBluetoothLeService.setCharacteristicNotification(bluetoothGattCharacteristicHM_10,true);                 }              }         }     };      // If a given GATT characteristic is selected, banking concern jibe for supported features.  This sample     // demonstrates 'Read' too 'Notify' features.  See     // http://d.android.com/reference/android/bluetooth/BluetoothGatt.html for the consummate     // listing of supported characteristic features.     mortal lastly ExpandableListView.OnChildClickListener servicesListClickListner =             novel ExpandableListView.OnChildClickListener() {                 @Override                 populace boolean onChildClick(ExpandableListView parent, View v, int groupPosition,                                             int childPosition, long id) {                     if (mGattCharacteristics != null) {                         lastly BluetoothGattCharacteristic characteristic =                                 mGattCharacteristics.get(groupPosition).get(childPosition);                         lastly int charaProp = characteristic.getProperties();                         if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {                             // If at that topographic point is an active notification on a characteristic, clear                             // it commencement too thence it doesn't update the information plain on the user interface.                             if (mNotifyCharacteristic != null) {                                 mBluetoothLeService.setCharacteristicNotification(                                         mNotifyCharacteristic, false);                                 mNotifyCharacteristic = null;                             }                             mBluetoothLeService.readCharacteristic(characteristic);                         }                         if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {                             mNotifyCharacteristic = characteristic;                             mBluetoothLeService.setCharacteristicNotification(                                     characteristic, true);                         }                         render true;                     }                     render false;                 }     };      mortal void clearUI() {         mGattServicesList.setAdapter((SimpleExpandableListAdapter) null);         mDataField.setText(R.string.no_data);     }      @Override     populace void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.gatt_services_characteristics);          lastly Intent intent = getIntent();         mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);         mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);          // Sets upwards UI references.         ((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress);         mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);         mGattServicesList.setOnChildClickListener(servicesListClickListner);         mConnectionState = (TextView) findViewById(R.id.connection_state);         mDataField = (TextView) findViewById(R.id.data_value);          getActionBar().setTitle(mDeviceName);         getActionBar().setDisplayHomeAsUpEnabled(true);         Intent gattServiceIntent = novel Intent(this, BluetoothLeService.class);         bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);     }      @Override     protected void onResume() {         super.onResume();         registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());         if (mBluetoothLeService != null) {             lastly boolean outcome = mBluetoothLeService.connect(mDeviceAddress);             Log.d(TAG, "Connect asking result=" + result);         }     }      @Override     protected void onPause() {         super.onPause();         unregisterReceiver(mGattUpdateReceiver);     }      @Override     protected void onDestroy() {         super.onDestroy();         unbindService(mServiceConnection);         mBluetoothLeService = null;     }      @Override     populace boolean onCreateOptionsMenu(Menu menu) {         getMenuInflater().inflate(R.menu.gatt_services, menu);         if (mConnected) {             menu.findItem(R.id.menu_connect).setVisible(false);             menu.findItem(R.id.menu_disconnect).setVisible(true);         } else {             menu.findItem(R.id.menu_connect).setVisible(true);             menu.findItem(R.id.menu_disconnect).setVisible(false);         }         render true;     }      @Override     populace boolean onOptionsItemSelected(MenuItem item) {         switch(item.getItemId()) {             instance R.id.menu_connect:                 mBluetoothLeService.connect(mDeviceAddress);                 render true;             instance R.id.menu_disconnect:                 mBluetoothLeService.disconnect();                 render true;             instance android.R.id.home:                 onBackPressed();                 render true;         }         render super.onOptionsItemSelected(item);     }      mortal void updateConnectionState(final int resourceId) {         runOnUiThread(new Runnable() {             @Override             populace void run() {                 mConnectionState.setText(resourceId);             }         });     }      mortal void displayData(String data) {         if (data != null) {             mDataField.setText(data);         }     }      // Demonstrates how to iterate through the supported GATT Services/Characteristics.     // In this sample, nosotros populate the information construction that is saltation to the ExpandableListView     // on the UI.     mortal void displayGattServices(List<BluetoothGattService> gattServices) {          UUID UUID_HM_10 =                 UUID.fromString(SampleGattAttributes.HM_10);          if (gattServices == null) return;         String uuid = null;         String unknownServiceString = getResources().getString(R.string.unknown_service);         String unknownCharaString = getResources().getString(R.string.unknown_characteristic);         ArrayList<HashMap<String, String>> gattServiceData = novel ArrayList<HashMap<String, String>>();         ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData                 = novel ArrayList<ArrayList<HashMap<String, String>>>();         mGattCharacteristics = novel ArrayList<ArrayList<BluetoothGattCharacteristic>>();          // Loops through available GATT Services.         for (BluetoothGattService gattService : gattServices) {             HashMap<String, String> currentServiceData = novel HashMap<String, String>();             uuid = gattService.getUuid().toString();             currentServiceData.put(                     LIST_NAME, SampleGattAttributes.lookup(uuid, unknownServiceString));             currentServiceData.put(LIST_UUID, uuid);             gattServiceData.add(currentServiceData);              ArrayList<HashMap<String, String>> gattCharacteristicGroupData =                     novel ArrayList<HashMap<String, String>>();             List<BluetoothGattCharacteristic> gattCharacteristics =                     gattService.getCharacteristics();             ArrayList<BluetoothGattCharacteristic> charas =                     novel ArrayList<BluetoothGattCharacteristic>();              // Loops through available Characteristics.             for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {                 charas.add(gattCharacteristic);                 HashMap<String, String> currentCharaData = novel HashMap<String, String>();                 uuid = gattCharacteristic.getUuid().toString();                 currentCharaData.put(                         LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString));                 currentCharaData.put(LIST_UUID, uuid);                 gattCharacteristicGroupData.add(currentCharaData);                  //Check if it is "HM_10"                 if(uuid.equals(SampleGattAttributes.HM_10)){                     bluetoothGattCharacteristicHM_10 = gattService.getCharacteristic(UUID_HM_10);                  }             }             mGattCharacteristics.add(charas);             gattCharacteristicData.add(gattCharacteristicGroupData);         }          SimpleExpandableListAdapter gattServiceAdapter = novel SimpleExpandableListAdapter(                 this,                 gattServiceData,                 android.R.layout.simple_expandable_list_item_2,                 novel String[] {LIST_NAME, LIST_UUID},                 novel int[] { android.R.id.text1, android.R.id.text2 },                 gattCharacteristicData,                 android.R.layout.simple_expandable_list_item_2,                 novel String[] {LIST_NAME, LIST_UUID},                 novel int[] { android.R.id.text1, android.R.id.text2 }         );         mGattServicesList.setAdapter(gattServiceAdapter);     }      mortal static IntentFilter makeGattUpdateIntentFilter() {         lastly IntentFilter intentFilter = novel IntentFilter();         intentFilter.addAction(BluetoothLeService.ACTION_GATT_CONNECTED);         intentFilter.addAction(BluetoothLeService.ACTION_GATT_DISCONNECTED);         intentFilter.addAction(BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED);         intentFilter.addAction(BluetoothLeService.ACTION_DATA_AVAILABLE);         render intentFilter;     } }  

t grip shipping information from Android to Bluetooth LE device Android shipping information to Bluetooth LE device, using HM-10 BLE ModuleDownload the files (Android Studio Format) .