Guest User

Untitled

a guest
Jun 10th, 2019
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. public void writeCustomCharacteristic(int value) {
  2.         if (mBluetoothAdapter == null || mBluetoothGatt == null) {
  3.             Log.w(TAG, "BluetoothAdapter not initialized");
  4.             return;
  5.         }
  6.         /*check if the service is available on the device*/
  7.         BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"));
  8.         if(mCustomService == null){
  9.             Log.w(TAG, "Custom BLE Service not found");
  10.             return;
  11.         }
  12.         /*get the read characteristic from the service*/
  13.         BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"));
  14.         mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
  15.         if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
  16.             Log.w(TAG, "Failed to write characteristic");
  17.         }
  18.     }
  19.  
  20. Below is my activity code:
  21.  
  22. public void onClickWrite(View v){
  23.         if(mBluetoothLeService != null) {
  24.             mBluetoothLeService.writeCustomCharacteristic(0x666666);
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment