List of usage examples for android.bluetooth BluetoothGattCharacteristic setValue
public boolean setValue(String value)
From source file:Main.java
/** * Write the given data to the beacon's advertising packet. * This only writes part 1 which is up to 20 bytes * of the packet data./*from w ww. j a v a 2 s .c o m*/ * * @param data */ private static void writeCharacteristic_beaconDataPart1(byte[] data) { // Get the characteristic for part 1 of the beacon data BluetoothGattCharacteristic characteristic_beaconDataPart1 = mBeaconBluetoothGattService .getCharacteristic(UUID_BEACON_DATA_PART_1); // Write the given byte array data to that characteristic characteristic_beaconDataPart1.setValue(data); // Write the updated characteristic via GATT mBluetoothGatt.writeCharacteristic(characteristic_beaconDataPart1); }
From source file:Main.java
/** * Write the given data to the beacon's advertising packet. * This only writes part 2 which is up to 8 bytes * of the packet data and is appended to the data from part 1. * * @param data/*from w w w. j a v a 2 s .c o m*/ */ private static void writeCharacteristic_beaconDataPart2(byte[] data) { // Get the characteristic for part 2 of the beacon data BluetoothGattCharacteristic characteristic_beaconDataPart2 = mBeaconBluetoothGattService .getCharacteristic(UUID_BEACON_DATA_PART_2); // Write the given byte array data to that characteristic characteristic_beaconDataPart2.setValue(data); // Write the updated characteristic via GATT mBluetoothGatt.writeCharacteristic(characteristic_beaconDataPart2); }
From source file:com.jameslandrum.bluetoothsmart.actions.SetCharacteristic.java
@Override public ActionError execute(SmartDevice smartDevice) { mError = super.execute(smartDevice); if (mError != null) return mError; if (mCharacteristic.getCharacteristic() == null) { mError = new Characteristic.CharacteristicNotFoundError(); return mError; }/*w w w.ja v a 2s . c o m*/ BluetoothGattCharacteristic characteristic = mCharacteristic.getCharacteristic(); characteristic.setValue(mData); smartDevice.addGattListener(this); mGatt.writeCharacteristic(characteristic); characteristic.setValue(mData); try { synchronized (mHolder) { mHolder.wait(300); } } catch (InterruptedException e) { mError = new CharacteristicWriteError(); } smartDevice.removeGattListener(this); if (mCompleteListener != null) mCompleteListener.onActionCompleted(this, mError == null); return mError; }
From source file:com.jameslandrum.bluetoothsmart.actions.LargeSetCharacteristic.java
@Override public ActionError execute(SmartDevice smartDevice) { mError = super.execute(smartDevice); if (mError != null) return mError; int index = 0; BluetoothGattCharacteristic characteristic = mCharacteristic.getCharacteristic(); characteristic.setValue(mData); smartDevice.addGattListener(this); try {/*from ww w. j a v a2 s .co m*/ while (index < mData.length) { if (!mDevice.isConnected()) { mError = new CharacteristicWriteError(); return mError; } int end = Math.min(index + mSize, mData.length); characteristic.setValue(Arrays.copyOfRange(mData, index, end)); mGatt.writeCharacteristic(characteristic); synchronized (mHolder) { mHolder.wait(300); } index += mSize; } } catch (Exception e) { mError = new CharacteristicWriteError(); } smartDevice.removeGattListener(this); if (mCompleteListener != null) mCompleteListener.onActionCompleted(this, mError == null); return mError; }
From source file:com.megster.cordova.rfduino.RFduinoPlugin.java
private void write(CallbackContext callbackContext, byte[] data) { BluetoothGattCharacteristic characteristic = activePeripheral.getSendCharacteristic(); characteristic.setValue(data); characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); boolean success = gatt.writeCharacteristic(characteristic); if (success) { callbackContext.success();//from w w w .ja va 2 s . c om } else { callbackContext.error("Write Failed"); } }
From source file:com.megster.cordova.rfduino.RFduinoPlugin.java
private void disconnect(CallbackContext callbackContext) { if (activePeripheral != null) { BluetoothGattCharacteristic characteristic = activePeripheral.getDisconnectCharacteristic(); characteristic.setValue(""); characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); gatt.writeCharacteristic(characteristic); activePeripheral.disconnect();// w ww. j av a2s .c om } if (gatt != null) { gatt.close(); gatt = null; } callbackContext.success(); }
From source file:io.v.android.libs.discovery.ble.BlePlugin.java
private BluetoothGattService convertToService(Advertisement adv) throws IOException { Map<UUID, byte[]> attributes = BleAdvertisementConverter.vAdvertismentToBleAttr(adv); BluetoothGattService service = new BluetoothGattService(UUIDUtil.UuidToUUID(adv.getServiceUuid()), BluetoothGattService.SERVICE_TYPE_PRIMARY); for (Map.Entry<UUID, byte[]> entry : attributes.entrySet()) { BluetoothGattCharacteristic ch = new BluetoothGattCharacteristic(entry.getKey(), 0, BluetoothGattCharacteristic.PERMISSION_READ); ch.setValue(entry.getValue()); service.addCharacteristic(ch);// w w w. ja v a 2s .c o m } return service; }
From source file:com.vehicle.uart.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 ww w . j av a 2 s.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); EVLog.e("write TXchar - status=" + status); }
From source file:com.wowwee.util.UartService.java
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;/*from ww w .ja v a2s . c o 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 TXchar - status= " + status); }
From source file:fr.bmartel.android.notti.service.bluetooth.BluetoothCustomManager.java
@SuppressLint("NewApi") @Override/*from ww w. ja v a 2 s . c o m*/ public void writeCharacteristic(String characUid, byte[] value, BluetoothGatt gatt, IPushListener listener) { if (gatt != null && characUid != null && value != null) { gattThreadPool.execute(new GattTask(gatt, characUid, value, listener) { @Override public void run() { BluetoothGattCharacteristic charac = GattUtils.getCharacteristic(getGatt().getServices(), getUid()); charac.setValue(getValue()); getGatt().writeCharacteristic(charac); long startTime = System.currentTimeMillis(); eventManager.reset(); try { eventManager.waitOne(BT_TIMEOUT); } catch (Exception e) { e.printStackTrace(); } long endTime = System.currentTimeMillis(); if ((endTime - startTime) >= BT_TIMEOUT) { if (getListener() != null) { getListener().onPushFailure(); } } else { if (getListener() != null) { getListener().onPushSuccess(); } } } }); gattThreadPool.execute(new Runnable() { @Override public void run() { } }); } else Log.e(TAG, "Error int writeCharacteristic() input argument NULL"); }