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_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;//from ww w .j a va 2 s .co 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:de.blinkt.openvpn.bluetooth.service.UartService.java
public void setDescriptor(BluetoothGattService rxService, UUID uuid) { CommonTools.delayTime(150);//from w w w . j a v a 2 s .co 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.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;/* w ww . j a v a 2 s .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:br.liveo.ndrawer.ui.activity.MainActivity.java
License:asdf
public int sendBlockingNotifySetting(bleRequest request) { request.status = bleRequestStatus.processing; int timeout = 0; if (request.characteristic == null) { return -1; }/*from ww w . ja v a 2 s . c o m*/ if (!checkGatt()) return -2; if (mGatt.setCharacteristicNotification(request.characteristic, request.notifyenable)) { BluetoothGattDescriptor clientConfig = request.characteristic .getDescriptor(GattInfo.CLIENT_CHARACTERISTIC_CONFIG); if (clientConfig != null) { if (request.notifyenable) { // Log.i(TAG, "Enable notification: " + // characteristic.getUuid().toString()); clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); } else { // Log.i(TAG, "Disable notification: " + // characteristic.getUuid().toString()); clientConfig.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); } mGatt.writeDescriptor(clientConfig); // Log.i(TAG, "writeDescriptor: " + // characteristic.getUuid().toString()); this.blocking = true; // Set read to be blocking while (this.blocking) { timeout++; waitIdle(1); if (timeout > GATT_TIMEOUT) { this.blocking = false; request.status = bleRequestStatus.timeout; return -1; } //Read failed TODO: Fix this to follow connection interval ! } request.status = bleRequestStatus.done; return lastGattStatus; } } return -3; // Set notification to android was wrong ... }
From source file:com.example.android.bluetoothlegatt.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 ww w . java 2s. co m public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } if (!mBluetoothGatt.setCharacteristicNotification(characteristic, enabled)) { Log.e(TAG, "setCharacteristicNotification fail! enabled=" + enabled); } if ((UUID.fromString("0000fff4-0000-1000-8000-00805f9b34fb")).equals(characteristic.getUuid())) { //mBluetoothGatt.writeCharacteristic(characteristic); List<BluetoothGattDescriptor> descs = characteristic.getDescriptors(); for (int i = 0; i < descs.size(); i++) { BluetoothGattDescriptor desc = descs.get(i); desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); Log.d(TAG, "writeDescriptor notify, uuid=" + desc.getUuid().toString()); mBluetoothGatt.writeDescriptor(desc); } //BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); //descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); //mBluetoothGatt.writeDescriptor(descriptor); } // 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.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 ava 2s . 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
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 ww . j a v a2s. 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 ww .ja v a 2s . c om } 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.jav a 2 s . c o 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); }
From source file:net.kenevans.android.blecardiacmonitor.BCMBleService.java
/** * Starts a session./*from w w w .java 2 s.c om*/ * * @param charBat The BAT characteristic. * @param charHr The HR characteristic. * @return If successful. (Always returns true) */ public boolean startSession(BluetoothGattCharacteristic charBat, BluetoothGattCharacteristic charHr) { Log.d(TAG, "startSession"); // Log.d(TAG, "startSession: mSessionState=" + mSessionState // + " mTimeoutTimer=" + mTimeoutTimer); // // 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); if (!mSessionInProgress) { mSessionStartTime = new Date().getTime(); } // // DEBUG Check permissions // checkPermissions(charBat, charHr, charCustom); // Stop notifying for existing characteristics if (mCharHr != null) { setCharacteristicNotification(mCharHr, 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; mLastBat = INVALID_INT; mLastHr = INVALID_INT; mLastRr = INVALID_STRING; mLastHrDate = new Date().getTime(); BluetoothGattDescriptor descriptor; if (mCharBat != null) { characteristicReadQueue.add(mCharBat); } if (mCharHr != null) { descriptor = mCharHr.getDescriptor(UUID_CLIENT_CHARACTERISTIC_CONFIG); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); descriptorWriteQueue.add(descriptor); setCharacteristicNotification(mCharHr, 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 = true; return true; }