List of usage examples for android.bluetooth BluetoothGattCharacteristic getDescriptor
public BluetoothGattDescriptor getDescriptor(UUID uuid)
From source file:com.guangyao.bluetoothtest.service.BluetoothLeService.java
/** * @brief enableTXNotification/* ww w .j av a 2 s .c o m*/ */ @SuppressLint("InlinedApi") public void enableTXNotification() { BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); if (RxService == null) { return; } BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID); if (TxChar == null) { return; } mBluetoothGatt.setCharacteristicNotification(TxChar, true); BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.ble.BLService.java
/** * Enables or disables notification on a give characteristic. * /*from ww w . j a v a 2 s . c o m*/ * @param characteristic * Characteristic to act on. * @param enabled * If true, enable notification. False otherwise. */ public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); if (UUID_STM32_ACCELEROMETER_PARAMETER.equals(characteristic.getUuid())) { BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID.fromString(BLGattAttributes.STM32_ACCELEROMETER_PARAMETER)); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } if (UUID_STM32_WRITE_TO_DEVICE.equals(characteristic.getUuid())) { BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID.fromString(BLGattAttributes.STM32_WRITE_TO_DEVICE)); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } }
From source file:com.chenls.smartlock.UartService.java
/** * ?//from ww w. j av a 2 s. c o m * Enable TXNotification * * @return */ public void enableTXNotification() { if (mBluetoothGatt == null) { showMessage("mBluetoothGatt null" + mBluetoothGatt); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID); if (TxChar == null) { showMessage("Tx charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } //characteristic?? mBluetoothGatt.setCharacteristicNotification(TxChar, true); BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.cqupt.sensor_ble.activity.UartService.java
/** * ?//from w w w . j a va 2 s . co m * Enable TXNotification */ public void enableTXNotification() { if (mBluetoothGatt == null) { showMessage("mBluetoothGatt null"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID); if (TxChar == null) { showMessage("Tx characteristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } //characteristic?? mBluetoothGatt.setCharacteristicNotification(TxChar, true); BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.example.bluetoothmodule.TreadmillService.java
private void Enable_HeartRate_CHARACTERISTIC_Notification() { BluetoothGattService TreadmillService = mBluetoothGatt.getService(HR_SERVICE_UUID); if (TreadmillService == null) { showMessage("HR_SERVICE service not found!"); return;// ww w . j a v a 2s. c o m } Log.i("Chandler", "Hr_SERVICE_UUID"); BluetoothGattCharacteristic Characteristic = TreadmillService.getCharacteristic(UUID_HR_CHARACTERISTIC); if (Characteristic == null) { showMessage("Hr charateristic not found!"); return; } mBluetoothGatt.setCharacteristicNotification(Characteristic, true); BluetoothGattDescriptor descriptor = Characteristic.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.example.bluetoothmodule.TreadmillService.java
private void Enable_SPEED_CHARACTERISTIC_Notification() { BluetoothGattService TreadmillService = mBluetoothGatt.getService(UUID_TREADMILL_SERVICE); if (TreadmillService == null) { showMessage("TREADMILL_SERVICE service not found!"); return;/*from w w w . j a v a 2s. c om*/ } BluetoothGattCharacteristic Characteristic = TreadmillService.getCharacteristic(UUID_SPEED_CHARACTERISTIC); if (Characteristic == null) { showMessage("SPEED charateristic not found!"); return; } mBluetoothGatt.setCharacteristicNotification(Characteristic, true); BluetoothGattDescriptor descriptor = Characteristic.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
@Override public void setNotification(JSONArray json, CallbackContext callbackContext) { Log.i(TAG, "setNotification"); String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS); if (connectedDevice.get(deviceAddress) == null) { Tools.sendErrorMsg(callbackContext); return;/*w ww. j a v a2s .c om*/ } int serviceIndex = Integer.parseInt(Tools.getData(json, Tools.SERVICE_INDEX)); int characteristicIndex = Integer.parseInt(Tools.getData(json, Tools.CHARACTERISTIC_INDEX)); String enable = Tools.getData(json, Tools.ENABLE); BluetoothGattCharacteristic characteristic = deviceServices.get(deviceAddress).get(serviceIndex) .getCharacteristics().get(characteristicIndex); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(Tools.NOTIFICATION_UUID); if (enable.equals("true")) { setNotificationCC.put(characteristic, callbackContext); if (Tools.lookup(characteristic.getProperties(), BluetoothGattCharacteristic.PROPERTY_NOTIFY) != null) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); } else { descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); } mBluetoothGatts.get(deviceAddress).writeDescriptor(descriptor); mBluetoothGatts.get(deviceAddress).setCharacteristicNotification(characteristic, true); recordServiceIndex.put(characteristic, serviceIndex); recordCharacteristicIndex.put(characteristic, characteristicIndex); } else { descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); mBluetoothGatts.get(deviceAddress).writeDescriptor(descriptor); mBluetoothGatts.get(deviceAddress).setCharacteristicNotification(characteristic, false); Tools.sendSuccessMsg(callbackContext); setNotificationCC.remove(characteristic); recordServiceIndex.remove(characteristic); recordCharacteristicIndex.remove(characteristic); } }
From source file:com.example.bluetoothmodule.TreadmillService.java
private void Enable_INCLINE_CHARACTERISTIC_Notification() { BluetoothGattService TreadmillService = mBluetoothGatt.getService(UUID_TREADMILL_SERVICE); if (TreadmillService == null) { showMessage("TREADMILL_SERVICE service not found!"); return;//from w w w . ja va2 s . com } BluetoothGattCharacteristic Characteristic = TreadmillService .getCharacteristic(UUID_INCLINE_CHARACTERISTIC); if (Characteristic == null) { showMessage("SPEED charateristic not found!"); return; } mBluetoothGatt.setCharacteristicNotification(Characteristic, true); BluetoothGattDescriptor descriptor = Characteristic.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.example.bluetoothmodule.TreadmillService.java
private void Enable_SportTime_CHARACTERISTIC_Notification() { BluetoothGattService TreadmillService = mBluetoothGatt.getService(UUID_TREADMILL_SERVICE); if (TreadmillService == null) { showMessage("TREADMILL_SERVICE service not found!"); return;/*from w w w . j a v a 2 s .c o m*/ } BluetoothGattCharacteristic Characteristic = TreadmillService .getCharacteristic(UUID_SPORT_TIME_CHARACTERISTIC); if (Characteristic == null) { showMessage("SPEED charateristic not found!"); return; } mBluetoothGatt.setCharacteristicNotification(Characteristic, true); BluetoothGattDescriptor descriptor = Characteristic.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.example.bluetoothmodule.TreadmillService.java
private void Enable_SportDistance_CHARACTERISTIC_Notification() { BluetoothGattService TreadmillService = mBluetoothGatt.getService(UUID_TREADMILL_SERVICE); if (TreadmillService == null) { showMessage("TREADMILL_SERVICE service not found!"); return;/* ww w.ja v a2s.co m*/ } BluetoothGattCharacteristic Characteristic = TreadmillService .getCharacteristic(UUID_SPORT_DISTANCE_CHARACTERISTIC); if (Characteristic == null) { showMessage("SPEED charateristic not found!"); return; } mBluetoothGatt.setCharacteristicNotification(Characteristic, true); BluetoothGattDescriptor descriptor = Characteristic.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }