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:Main.java
public static boolean enableNotification(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { BluetoothGattDescriptor descriptor = configDescriptor(characteristic); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); return gatt.setCharacteristicNotification(characteristic, true) && gatt.writeDescriptor(descriptor); }
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 w ww. j a v a 2s . 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.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 {/* w ww . j av a 2 s . c om*/ 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:net.emilymaier.movebot.HeartFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.main_heart, container, false); heartScan = (Button) rootView.findViewById(R.id.heartScan); heartList = (ListView) rootView.findViewById(R.id.heartList); heartDevices = new ArrayList<>(); heartListAdapter = new ArrayAdapter<>(act, android.R.layout.simple_list_item_1, heartDevices); heartList.setAdapter(heartListAdapter); heartList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w ww . j a v a2s.c om public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.d("HeartFragment", "Selecting device"); for (HeartDevice device : heartDevices) { device.bluetoothGatt.setCharacteristicNotification(device.characteristic, false); } HeartDevice device = heartDevices.get(position); device.bluetoothGatt.setCharacteristicNotification(device.characteristic, true); BluetoothGattDescriptor descriptor = device.characteristic .getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); device.bluetoothGatt.writeDescriptor(descriptor); } }); heartScan.setOnClickListener(this); return rootView; }
From source file:fr.bmartel.android.bluetooth.connection.BluetoothDeviceConn.java
@SuppressLint("NewApi") @Override/* w w w. ja v a2 s .c om*/ public void enableGattNotifications(String serviceUid, String characUid) { String descriptorStr = BluetoothConst.CLIENT_CHARACTERISTIC_CONFIG; manager.writeDescriptor(descriptorStr, gatt, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE, serviceUid, characUid); }
From source file:com.github.akinaru.bleanalyzer.bluetooth.connection.BluetoothDeviceConn.java
@SuppressLint("NewApi") @Override//from www . j a va 2 s. c o m public void enableGattNotifications(String serviceUid, String characUid) { String descriptorStr = CLIENT_CHARACTERISTIC_CONFIG; manager.writeDescriptor(descriptorStr, gatt, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE, serviceUid, characUid); }
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 w w . j ava 2 s . c o m } 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.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 . j av a2s .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.example.user.wase.view.fragment.EquipmentScanner.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;// w ww .j av a2 s . c o m String uuid = null; ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>(); // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { HashMap<String, String> currentServiceData = new HashMap<String, String>(); uuid = gattService.getUuid().toString(); currentServiceData.put(LIST_NAME, HERE_GattAttributes.lookup(uuid, "unknown")); // If the service exists for HM 10 Serial, say so. if (HERE_GattAttributes.lookup(uuid, "unknown") == "HM 10 Serial") { } else { } currentServiceData.put(LIST_UUID, uuid); gattServiceData.add(currentServiceData); // get characteristic when UUID matches RX/TX UUID characteristicTX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX); characteristicRX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX); if (characteristicTX != null && mBluetoothLeService != null) { characteristicRX.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothLeService.writeCharacteristic(characteristicTX); mBluetoothLeService.setCharacteristicNotification(characteristicRX, true); } } }
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 ww w.j a va 2 s . co m*/ 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); } }