List of usage examples for android.bluetooth BluetoothGattDescriptor ENABLE_NOTIFICATION_VALUE
null ENABLE_NOTIFICATION_VALUE
To view the source code for android.bluetooth BluetoothGattDescriptor ENABLE_NOTIFICATION_VALUE.
Click Source Link
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;/*w w w. ja v a2 s . co 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.guangyao.bluetoothtest.service.BluetoothLeService.java
/** * @brief enableTXNotification// w w w. j a v a 2s.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.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;//from w ww.ja v a2s . 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:net.kenevans.android.hxmmonitor.HxMBleService.java
/** * Starts a session.//from w w w .j ava 2 s. co m * * @param charBat * @param charHr * @param charCustom * @return If successful. */ public boolean startSession(BluetoothGattCharacteristic charBat, BluetoothGattCharacteristic charHr, BluetoothGattCharacteristic charCustom, boolean doBat, boolean doHr, boolean doCustom) { Log.d(TAG, "startSession"); // Log.d(TAG, "startSession: mSessionState=" + mSessionState // + " mTimeoutTimer=" + mTimeoutTimer); mDoBat = doBat; mDoHr = doHr; mDoCustom = doCustom; // // DEBUG // String batVal = mCharBat == null ? "null" : String.format("%8x", // mCharBat.hashCode()); // String hrVal = mCharHr == null ? "null" : String.format("%8x", // mCharHr.hashCode()); // String customVal = mCharCustom == null ? "null" : // String.format("%8x", // mCharCustom.hashCode()); // Log.d(TAG, " mCharBat=" + batVal + " mCharHr=" + hrVal // + " mCharCustom=" + customVal); // batVal = charBat == null ? "null" : String.format("%8x", // charBat.hashCode()); // hrVal = charHr == null ? "null" : String.format("%8x", // charHr.hashCode()); // customVal = charCustom == null ? "null" : String.format("%8x", // charCustom.hashCode()); // Log.d(TAG, " charBat=" + batVal + " charHr=" + hrVal + // " charCustom=" // + customVal); // Log.d(TAG, " mDoBat=" + mDoBat + " mDoHr=" + mDoHr + " mDoCustom=" // + mDoCustom); boolean res = true; mSessionStartTime = new Date().getTime(); // // DEBUG Check permissions // checkPermissions(charBat, charHr, charCustom); // Stop notifying for existing characteristics if (mCharHr != null) { setCharacteristicNotification(mCharHr, false); } if (mCharCustom != null) { setCharacteristicNotification(mCharCustom, false); } // Clear any queues while (descriptorWriteQueue.size() > 0) { descriptorWriteQueue.remove(); } while (characteristicReadQueue.size() > 0) { characteristicReadQueue.remove(); } // Initialize for the new values mCharBat = charBat; mCharHr = charHr; mCharCustom = charCustom; mLastBat = INVALID_INT; mLastHr = INVALID_INT; mLastRr = INVALID_STRING; mLastHrDate = new Date().getTime(); mLastAct = INVALID_INT; mLastPa = INVALID_INT; BluetoothGattDescriptor descriptor; if (mCharBat != null && mDoBat) { characteristicReadQueue.add(mCharBat); } if (mCharHr != null && mDoHr) { descriptor = mCharHr.getDescriptor(UUID_CLIENT_CHARACTERISTIC_CONFIG); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); descriptorWriteQueue.add(descriptor); setCharacteristicNotification(mCharHr, true); } if (mCharCustom != null && mDoCustom) { descriptor = mCharCustom.getDescriptor(UUID_CLIENT_CHARACTERISTIC_CONFIG); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); descriptorWriteQueue.add(descriptor); setCharacteristicNotification(mCharCustom, true); } // Start the queues. Do writeDescriptors before any readCharacteristics if (descriptorWriteQueue.size() > 0) { mBluetoothGatt.writeDescriptor(descriptorWriteQueue.element()); } else if (characteristicReadQueue.size() > 0) { mBluetoothGatt.readCharacteristic(characteristicReadQueue.element()); } mSessionInProgress = res; return res; }
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. */// w ww . j a v a2s. 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// ww w . ja v a2 s .c o m * */ 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(); } } } }
From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java
private boolean enableDfuNotification() { Log.d(TAG, "enableDfuNotification"); if (mDfuChar == null) { Log.w(TAG, "enableDfuNotification: DFU control point characteristic not initiated"); return false; }//from ww w. j a va 2s . c o m BluetoothGattDescriptor dfuDesc = mDfuChar .getDescriptor(GattAttributeUUID.UUID_DFU_CONTROL_POINT_DESCRIPTOR); if (dfuDesc == null || !dfuDesc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) || !mBluetoothGattClient.writeDescriptor(dfuDesc)) { Log.e(TAG, "enableDfuNotification: Failed to init DFU descriptor write operation"); return false; } return true; }
From source file:com.umundus.service.NCallServiceOld.java
/** * Enabl Battery Notification//from w ww . j a v a2 s . c o 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:no.nordicsemi.android.nrftoolbox.dfu.DfuService.java
/** * Enables or disables the notifications for given characteristic. This method is SYNCHRONOUS and wait until the * {@link BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int)} will be called or the connection state will change from {@link #STATE_CONNECTED_AND_READY}. If * connection state will change, or an error will occur, an exception will be thrown. * // w w w .ja v a2s .co m * @param gatt * the GATT device * @param characteristic * the characteristic to enable or disable notifications for * @param enable * <code>true</code> to enable notifications, <code>false</code> to disable them * @throws DfuException * @throws UploadAbortedException */ private void setCharacteristicNotification(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final boolean enable) throws DeviceDisconnectedException, DfuException, UploadAbortedException { if (mConnectionState != STATE_CONNECTED_AND_READY) throw new DeviceDisconnectedException("Unable to set notifications state", mConnectionState); mErrorState = 0; if (mNotificationsEnabled == enable) return; logi((enable ? "Enabling " : "Disabling") + " notifications..."); // enable notifications locally gatt.setCharacteristicNotification(characteristic, enable); // enable notifications on the device final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG); descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); gatt.writeDescriptor(descriptor); // We have to wait until device gets disconnected or an error occur try { synchronized (mLock) { while ((mNotificationsEnabled != enable && mConnectionState == STATE_CONNECTED_AND_READY && mErrorState == 0 && !mAborted) || mPaused) mLock.wait(); } } catch (final InterruptedException e) { loge("Sleeping interrupted", e); } if (mAborted) throw new UploadAbortedException(); if (mErrorState != 0) throw new DfuException("Unable to set notifications state", mErrorState); if (mConnectionState != STATE_CONNECTED_AND_READY) throw new DeviceDisconnectedException("Unable to set notifications state", mConnectionState); }