List of usage examples for android.bluetooth BluetoothGattCharacteristic getDescriptor
public BluetoothGattDescriptor getDescriptor(UUID uuid)
From source file:Main.java
public static BluetoothGattDescriptor configDescriptor(BluetoothGattCharacteristic characteristic) { return characteristic.getDescriptor(CONFIG_DESCRIPTOR_UUID); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) static boolean setCharacteristicNotification(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, boolean isEnabled) { if (characteristic != null) { gatt.setCharacteristicNotification(characteristic, isEnabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(DEVICE_CONFIG_CHARACTERISTIC); if (descriptor != null) { descriptor.setValue(/*from ww w .j a v a 2 s .c o m*/ isEnabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 }); return gatt.writeDescriptor(descriptor); } else return false; } else return false; }
From source file:com.xtremeprog.sdk.ble.SamsungBle.java
@Override public boolean characteristicNotification(String address, BleGattCharacteristic characteristic) { BluetoothGattCharacteristic c = characteristic.getGattCharacteristicS(); if (!mBluetoothGatt.setCharacteristicNotification(c, true)) { return false; }/*w w w . j av a 2s .c o m*/ BluetoothGattDescriptor descriptor = c.getDescriptor(BleService.DESC_CCC); if (descriptor == null) { return false; } return mBluetoothGatt.readDescriptor(descriptor); }
From source file:ble.AndroidBle.java
@Override public boolean characteristicNotification(String address, BleGattCharacteristic characteristic) { BleRequest request = mService.getCurrentRequest(); BluetoothGatt gatt = mBluetoothGatts.get(address); if (gatt == null || characteristic == null) { return false; }// w w w . j a v a2s . com boolean enable = true; if (request.type == RequestType.CHARACTERISTIC_STOP_NOTIFICATION) { enable = false; } BluetoothGattCharacteristic c = characteristic.getGattCharacteristicA(); if (!gatt.setCharacteristicNotification(c, enable)) { return false; } BluetoothGattDescriptor descriptor = c.getDescriptor(BleService.DESC_CCC); if (descriptor == null) { return false; } byte[] val_set = null; if (request.type == RequestType.CHARACTERISTIC_NOTIFICATION) { val_set = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE; } else if (request.type == RequestType.CHARACTERISTIC_INDICATION) { val_set = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE; } else { val_set = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE; } if (!descriptor.setValue(val_set)) { return false; } return gatt.writeDescriptor(descriptor); }
From source file:com.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java
/** * prepare notifications of all Report characteristic found from the service *//*w w w . ja va 2 s .co m*/ private void prepareBroadcastAllNotifications() { mProgressDialog.setTitle(getResources().getString(R.string.alert_message_prepare_title)); mProgressDialog.setMessage(getResources().getString(R.string.alert_message_prepare_message) + "\n" + getResources().getString(R.string.alert_message_wait)); mProgressDialog.setCancelable(false); mProgressDialog.show(); for (int pos = 0; pos < charaDataModel.size(); pos++) { final BluetoothGattCharacteristic characteristic = charaDataModel.get(pos).getmGattCharacteristic(); if (characteristic.getDescriptor(UUIDDatabase.UUID_REPORT_REFERENCE) != null) { new Handler().postDelayed(new Runnable() { @Override public void run() { if (HANDLER_FLAG) { BluetoothLeService.setCharacteristicNotification(characteristic, true); } } }, HANDLER_DELAY * pos); } } new Handler().postDelayed(new Runnable() { @Override public void run() { if (HANDLER_FLAG) { mProgressDialog.dismiss(); getActivity().registerReceiver(mGattUpdateReceiver, Utils.makeGattUpdateIntentFilter()); mNotiificationsEnabled = true; } } }, HANDLER_DELAY * 6); }
From source file:com.megster.cordova.rfduino.Peripheral.java
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { Log.d(TAG, "gatt " + gatt); Log.d(TAG, "status " + status); super.onServicesDiscovered(gatt, status); BluetoothGattService service = gatt.getService(RFDUINO_SERVICE_UUID); Log.d(TAG, "service " + service); BluetoothGattCharacteristic receiveCharacteristic = service.getCharacteristic(RECEIVE_CHARACTERISTIC_UUID); sendCharacteristic = service.getCharacteristic(SEND_CHARACTERISTIC_UUID); disconnectCharacteristic = service.getCharacteristic(DISCONNECT_CHARACTERISTIC_UUID); if (receiveCharacteristic != null) { gatt.setCharacteristicNotification(receiveCharacteristic, true); BluetoothGattDescriptor receiveConfigDescriptor = receiveCharacteristic .getDescriptor(CLIENT_CHARACTERISTIC_CONFIGURATION_UUID); if (receiveConfigDescriptor != null) { receiveConfigDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); gatt.writeDescriptor(receiveConfigDescriptor); } else {//from www .j av a 2 s . co m LOG.e(TAG, "Receive Characteristic can not be configured."); } } else { LOG.e(TAG, "Receive Characteristic is missing."); } // call the success callback for connect PluginResult result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(true); connectCallback.sendPluginResult(result); }
From source file:com.github.w666.ezonwatch.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 ww . ja v a 2 s.com*/ public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); if (characteristic.getUuid().equals(UUID_EZON_MAIN)) { BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); descriptor.setValue( enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 }); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } }
From source file:com.example.alexanderbolinsky.ble_uart_remote.UartService.java
/** * Enable TXNotification/*from ww w . j ava 2 s . c o m*/ * * @return */ public void enableTXNotification() { 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; } mBluetoothGatt.setCharacteristicNotification(TxChar, true); BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.shenqu.jlplayer.nRFUARTv2.UartService.java
/** * Enable TXNotification/*w w w. j a v a 2s . com*/ * * @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; } mBluetoothGatt.setCharacteristicNotification(TxChar, true); BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.example.alan.bikelog.UartService.java
/** * Enable TXNotification/*from ww w. jav a2s . c o m*/ * * @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; } mBluetoothGatt.setCharacteristicNotification(TxChar, true); BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }