List of usage examples for android.bluetooth BluetoothGattCharacteristic getDescriptor
public BluetoothGattDescriptor getDescriptor(UUID uuid)
From source file:com.example.bluetoothmodule.TreadmillService.java
private void Enable_SporCalories_CHARACTERISTIC_Notification() { BluetoothGattService TreadmillService = mBluetoothGatt.getService(UUID_TREADMILL_SERVICE); if (TreadmillService == null) { showMessage("TREADMILL_SERVICE service not found!"); return;/*from w ww . ja v a 2 s .c o m*/ } BluetoothGattCharacteristic Characteristic = TreadmillService .getCharacteristic(UUID_SPORT_CALORIES_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.qi.airstat.BluetoothLeService.java
/** * Enables or disables notification on a give characteristic. * * @param characteristic Characteristic to act on. * @param enabled If true, enable notification. False otherwise. *//*from w w w . j a va 2 s .c o m*/ public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not 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); } }
From source file:com.example.bluetoothmodule.TreadmillService.java
/** * Enable TXNotification/* w w w . j a v a 2 s . c o m*/ * * @return */ private void enableTXNotification() { BluetoothGattService RxService = mBluetoothGatt.getService(UUID_TREADMILL_SERVICE); 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; } Log.i("Chandler", "RX_SERVICE_UUID"); 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_DISPLAY_STATE_CHARACTERISTIC_Notification() { BluetoothGattService TreadmillService = mBluetoothGatt.getService(UUID_TREADMILL_SERVICE); if (TreadmillService == null) { showMessage("Rx service not found!"); //broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return;// w w w . ja v a 2 s.c o m } BluetoothGattCharacteristic Characteristic = TreadmillService .getCharacteristic(UUID_DISPLAY_STATE_CHARACTERISTIC); if (Characteristic == null) { showMessage("DISPLAY STATE charateristic not found!"); //broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } Log.i("Chandler", "UUID_DISPLAY_STATE_CHARACTERISTIC"); mBluetoothGatt.setCharacteristicNotification(Characteristic, true); BluetoothGattDescriptor descriptor = Characteristic.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.megster.cordova.ble.central.Peripheral.java
private void registerNotifyCallback(CallbackContext callbackContext, UUID serviceUUID, UUID characteristicUUID) { boolean success = false; if (gatt == null) { callbackContext.error("BluetoothGatt is null"); return;//w w w . java2 s .c o m } BluetoothGattService service = gatt.getService(serviceUUID); BluetoothGattCharacteristic characteristic = findNotifyCharacteristic(service, characteristicUUID); String key = generateHashKey(serviceUUID, characteristic); if (characteristic != null) { notificationCallbacks.put(key, callbackContext); if (gatt.setCharacteristicNotification(characteristic, true)) { // Why doesn't setCharacteristicNotification write the descriptor? BluetoothGattDescriptor descriptor = characteristic .getDescriptor(CLIENT_CHARACTERISTIC_CONFIGURATION_UUID); if (descriptor != null) { // prefer notify over indicate if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); } else if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); } else { LOG.w(TAG, "Characteristic " + characteristicUUID + " does not have NOTIFY or INDICATE property set"); } if (gatt.writeDescriptor(descriptor)) { success = true; } else { callbackContext.error( "Failed to set client characteristic notification for " + characteristicUUID); } } else { callbackContext.error("Set notification failed for " + characteristicUUID); } } else { callbackContext.error("Failed to register notification for " + characteristicUUID); } } else { callbackContext.error("Characteristic " + characteristicUUID + " not found"); } if (!success) { commandCompleted(); } }
From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java
public void readClientCharacteristicConfig(String address, BluetoothGattCharacteristic characteristic) { if (StringUtils.isEmptyString(address)) { Log.w(TAG, "Unknown address"); }/*from w ww. j ava 2 s . co m*/ BluetoothGatt bluetoothGatt = mConnectedBluetoothGattMap.get(address); BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); boolean readDescriptorResult = bluetoothGatt.readDescriptor(descriptor); Log.d(TAG, "readDescriptorResult = " + readDescriptorResult); }
From source file:de.blinkt.openvpn.bluetooth.service.UartService.java
public void setDescriptor(BluetoothGattService rxService, UUID uuid) { CommonTools.delayTime(150);//from w ww. j ava 2 s . c o m BluetoothGattCharacteristic TxChar = rxService.getCharacteristic(uuid); if (TxChar == null) { showMessage("Tx charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } // final int rxProperties = TxChar.getProperties(); // boolean writeRequest = (rxProperties & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0; // // // Set the WRITE REQUEST type when the characteristic supports it. This will allow to send long write (also if the characteristic support it). // // In case there is no WRITE REQUEST property, this manager will divide texts longer then 20 bytes into up to 20 bytes chunks. // if (writeRequest) // TxChar.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT); mBluetoothGatt.setCharacteristicNotification(TxChar, true); BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); // mBluetoothGatt.readDescriptor(descriptor); mBluetoothGatt.writeDescriptor(descriptor); //?? broadcastUpdate(FINDED_SERVICE); }
From source file:com.umundus.service.NCallServiceOld.java
/** * Enabl Battery Notification//from w w w.ja v a 2 s . co m * */ public void enableBatteryNotification() { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "enableBatteryNotification BluetoothAdapter not initialized"); return; } BluetoothGattService BatteryService = mBluetoothGatt.getService(BATTERY_SERVICE); if (BatteryService == null) { showMessage("Battery service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_SRC); return; } BluetoothGattCharacteristic BatteryChar = BatteryService.getCharacteristic(BATTERY_CHARACTERISTIC); if (BatteryChar == null) { showMessage("Battery charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_SRC); return; } mBluetoothGatt.setCharacteristicNotification(BatteryChar, true); mRequestCompleted = false; BluetoothGattDescriptor descriptor = BatteryChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); synchronized (mLock) { if (!mRequestCompleted && mConnectionState == STATE_DISCOVERED) { try { mLock.wait(); // onDescriptorWrite ? notify . } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java
/** * Enables or disables notification on a give characteristic. * * @param enabled If true, enable notification. False otherwise. *///from w w w .j a v a 2 s.c o m public boolean setCharacteristicNotification(String address, String serviceUuid, String characteristicUuid, boolean enabled) { Log.d(TAG, "writeRemoteCharacteristic add = " + address + ", svc = " + serviceUuid + ", char = " + characteristicUuid); if (StringUtils.isEmptyString(address) || StringUtils.isEmptyString(serviceUuid) || StringUtils.isEmptyString(characteristicUuid)) { Log.w(TAG, "Unknown parameter"); return false; } BluetoothGatt bluetoothGatt = mConnectedBluetoothGattMap.get(address); if (mBluetoothAdapter == null || bluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return false; } BluetoothGattService service = bluetoothGatt.getService(UUID.fromString(serviceUuid)); if (service == null) { Log.w(TAG, "Service not found."); return false; } BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString(characteristicUuid)); if (characteristic == null) { Log.w(TAG, "characteristic not found."); return false; } bluetoothGatt.setCharacteristicNotification(characteristic, enabled); final int charaProp = characteristic.getProperties(); if ((charaProp & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); if (descriptor != null) { Log.d(TAG, ">>>> ENABLE_NOTIFICATION_VALUE : " + characteristic.getUuid().toString()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); bluetoothGatt.writeDescriptor(descriptor); return true; } else { return false; } } else if ((charaProp & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) { BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); if (descriptor != null) { Log.d(TAG, ">>>> ENABLE_INDICATION_VALUE : " + characteristic.getUuid().toString()); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); bluetoothGatt.writeDescriptor(descriptor); return true; } else { return false; } } else { return false; } }
From source file:com.umundus.service.NCallServiceOld.java
/** * Enable Key Button Notification/* www . j a va2s .c om*/ * */ public void enableKeyInputNotification() { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "enableKeyInputNotification BluetoothAdapter not initialized"); return; } BluetoothGattService KeyInputService = mBluetoothGatt.getService(NCALL_REMOCON_SERVICE); if (KeyInputService == null) { showMessage("key input service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_SRC); return; } // ? KEY ? ?? . BluetoothGattCharacteristic KeyInputChar = KeyInputService .getCharacteristic(NCALL_REMOCON_KEY_NOTI_CHARACTERISTIC); if (KeyInputChar == null) { showMessage("Key input charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_SRC); return; } mRequestCompleted = false; mBluetoothGatt.setCharacteristicNotification(KeyInputChar, true); BluetoothGattDescriptor descriptor = KeyInputChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); synchronized (mLock) { if (!mRequestCompleted && mConnectionState == STATE_DISCOVERED) { try { mLock.wait(); // onDescriptorWrite ? notify . } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }