List of usage examples for android.bluetooth BluetoothGattService getCharacteristic
public BluetoothGattCharacteristic getCharacteristic(UUID uuid)
From source file:com.sdingba.su.alphabet_demotest.view.lanya.UartService.java
/** * Enable TXNotification// ww w .j av a2 s . com * * @return */ public void enableTXNotification() { Log.d(TAG, "SDingBaLanYan : enableTXNotification "); if (mBluetoothGatt == null) { showMessage("mBluetoothGatt(is null) = null" + mBluetoothGatt); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); if (RxService == null) { showMessage("Rx service not found!---RX_SERVICE_UUID"); 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.UART.UartService.java
@SuppressLint("NewApi") public void writeRXCharacteristic(byte[] value) { BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); showMessage("mBluetoothGatt null" + mBluetoothGatt); if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return;//from ww w . j av a 2s. com } BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID); if (RxChar == null) { showMessage("Rx charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } RxChar.setValue(value); boolean status = mBluetoothGatt.writeCharacteristic(RxChar); Log.d(TAG, "write TXchar - status=" + status); }
From source file:de.blinkt.openvpn.bluetooth.service.UartService.java
/** * When the device is bonded and has the Generic Attribute service and the Service Changed characteristic this method enables indications on this characteristic. * In case one of the requirements is not fulfilled this method returns <code>false</code>. * * @return <code>true</code> when the request has been sent, <code>false</code> when the device is not bonded, does not have the Generic Attribute service, the GA service does not have * the Service Changed characteristic or this characteristic does not have the CCCD. *///from www . jav a2s .co m public boolean ensureServiceChangedEnabled() { final BluetoothGatt gatt = mBluetoothGatt; if (gatt == null) return false; // The Service Changed indications have sense only on bonded devices final BluetoothDevice device = gatt.getDevice(); if (device.getBondState() != BluetoothDevice.BOND_BONDED) return false; final BluetoothGattService gaService = gatt.getService(GENERIC_ATTRIBUTE_SERVICE); if (gaService == null) return false; final BluetoothGattCharacteristic scCharacteristic = gaService .getCharacteristic(SERVICE_CHANGED_CHARACTERISTIC); return scCharacteristic != null; }
From source file:com.example.kevin.health.ble.UartService.java
public void writeRXCharacteristic(byte[] value) { BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); showMessage("mBluetoothGatt null" + mBluetoothGatt); if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT); return;/*from w w w . j a va2 s . c o m*/ } BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID); if (RxChar == null) { showMessage("Rx charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT); return; } RxChar.setValue(value); boolean status = mBluetoothGatt.writeCharacteristic(RxChar); Log.d(TAG, "write TXchar - status=" + status); }
From source file:com.cqupt.sensor_ble.activity.UartService.java
/** * ???/*w w w . j a va 2s.co m*/ * * @param value value */ public void writeRXCharacteristic(byte[] value) { BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID); if (RxChar == null) { showMessage("Rx characteristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } RxChar.setValue(value); boolean status = mBluetoothGatt.writeCharacteristic(RxChar); Log.d(TAG, "write TXChar - status=" + status); }
From source file:com.chenls.smartlock.UartService.java
/** * ???/*ww w. j a v a2s .c om*/ * * @param value */ public void writeRXCharacteristic(byte[] value) { BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID); if (RxChar == null) { showMessage("Rx charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } RxChar.setValue(value); boolean status = mBluetoothGatt.writeCharacteristic(RxChar); Log.d(TAG, "write TXchar - status=" + status); }
From source file:com.cqupt.sensor_ble.activity.UartService.java
/** * ?/*from w ww . j a v a 2s .c o m*/ * Enable TXNotification */ public void enableTXNotification() { if (mBluetoothGatt == null) { showMessage("mBluetoothGatt null"); 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 characteristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } //characteristic?? mBluetoothGatt.setCharacteristicNotification(TxChar, true); BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.chenls.smartlock.UartService.java
/** * ?// www.j a v a 2s .c o m * Enable TXNotification * * @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; } //characteristic?? mBluetoothGatt.setCharacteristicNotification(TxChar, true); BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); }
From source file:com.example.kevin.health.UartService.java
public void writeRXCharacteristic(byte[] value) { if (mBluetoothGatt != null) { BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); showMessage("mBluetoothGatt null" + mBluetoothGatt); if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT); return; }/* w ww . j av a2 s . c om*/ BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID); if (RxChar == null) { showMessage("Rx charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT); return; } RxChar.setValue(value); boolean status = mBluetoothGatt.writeCharacteristic(RxChar); Log.d(TAG, "write TXchar - status=" + status); } }
From source file:com.nordicsemi.UART_UDP_PROXY.UartService.java
public void writeRXCharacteristic(byte[] value) { BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID); showMessage("mBluetoothGatt null" + mBluetoothGatt); if (RxService == null) { showMessage("Rx service not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return;//from w w w . j a v a2s .co m } BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID); if (RxChar == null) { showMessage("Rx charateristic not found!"); broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART); return; } RxChar.setValue(value); boolean status = mBluetoothGatt.writeCharacteristic(RxChar); Log.d(TAG, "write RXchar - status=" + status); }