Example usage for android.bluetooth BluetoothGattService getCharacteristic

List of usage examples for android.bluetooth BluetoothGattService getCharacteristic

Introduction

In this page you can find the example usage for android.bluetooth BluetoothGattService getCharacteristic.

Prototype

public BluetoothGattCharacteristic getCharacteristic(UUID uuid) 

Source Link

Document

Returns a characteristic with a given UUID out of the list of characteristics offered by this service.

Usage

From source file:com.github.vgoliveira.panificadora.UartService.java

public void writeRXCharacteristic(byte[] value) {

    BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID);
    if (RxService == null) {
        Log.d(TAG, "Rx service not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;/* w ww. j a  v a 2s  .  c o m*/
    }
    BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID);
    if (RxChar == null) {
        showMessage("Rx charateristic not found!");
        Log.d(TAG, "Rx service not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }
    boolean status_value_set = RxChar.setValue(value);
    boolean status_write = mBluetoothGatt.writeCharacteristic(RxChar);

    Log.d(TAG, "write RXchar set value - status=" + status_value_set);
    Log.d(TAG, "write RXchar - status=" + status_write);
    Log.d(TAG, "write RXchar - value[0/1]=" + value[0] + "/" + value[1]);
}

From source file:com.pandadentist.service.UartService.java

/**
 * Enable TXNotification/* w  w  w.  j ava2s  .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);

}

From source file:com.chenls.smartlock.UartService.java

public void readCharacteristic(UUID uuid1, UUID uuid2) {

    BluetoothGattService batteryService = mBluetoothGatt.getService(uuid1);
    if (batteryService == null) {
        return;/*  w w w. j av a2  s.c  o m*/
    }
    BluetoothGattCharacteristic batteryLevel = batteryService.getCharacteristic(uuid2);
    if (batteryLevel == null) {
        return;
    }
    mBluetoothGatt.readCharacteristic(batteryLevel);
}

From source file:com.github.vgoliveira.panificadora.UartService.java

/**
 * Enable TXNotification//from  ww w .jav a 2  s  .  c  o m
 *
 * @return
 */

// No est sendo usadada na verso autal
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.huiwu.bluetooth.BluetoothService.java

/**
 * Enable TXNotification/*  ww w.  j  av a  2  s.  co  m*/
 *
 * @return
 */
public void enableTXNotification(boolean enable) {
    /*
    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);
    if (enable) {
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    } else {
        descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
    }
    mBluetoothGatt.writeDescriptor(descriptor);

}

From source file:com.example.UART.UartService.java

/**
 * Enable TXNotification//from  w  ww  .  ja va  2s  .  co m
 *
 * @return 
 */
@SuppressLint("NewApi")
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.kraker.myocmd.TestService1.DeviceControlActivity.java

private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null)
        return;//w ww.j  av a2s  . co  m
    String uuid = null;
    String unknownServiceString = getResources().getString(R.string.unknown_service);
    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, SampleGattAttributes.lookup(uuid, unknownServiceString));
        currentServiceData.put(LIST_UUID, uuid);
        gattServiceData.add(currentServiceData);
        characteristicTX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX);
        characteristicRX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX);
    }
}

From source file:de.blinkt.openvpn.bluetooth.service.UartService.java

public void setDescriptor(BluetoothGattService rxService, UUID uuid) {
    CommonTools.delayTime(150);/*from ww w  . j a  v  a 2  s. c o 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.aprilbrother.blueduino.UartService.java

/**
 * Enable TXNotification/*from   w w w. j av  a2  s.  c  om*/
 * 
 * @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.kevin.health.ble.UartService.java

/**
 * Enable TXNotification/*w  ww. ja v  a  2s .  c  o  m*/
 *
 * @return 
 */
public void enableHRNotification() {
    /*
    if (mBluetoothGatt == null) {
       showMessage("mBluetoothGatt null" + mBluetoothGatt);
       broadcastUpdate(DEVICE_DOES_NOT_SUPPORT);
       return;
    }
       */
    BluetoothGattService HRService = mBluetoothGatt.getService(HR_SERVICE_UUID);
    if (HRService == null) {
        showMessage("HR service not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT);
        return;
    }
    BluetoothGattCharacteristic TxChar = HRService.getCharacteristic(HR_CHAR_UUID);
    if (TxChar == null) {
        showMessage("HR charateristic not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT);
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);

    BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);
}