List of usage examples for android.bluetooth BluetoothGattCharacteristic FORMAT_UINT32
int FORMAT_UINT32
To view the source code for android.bluetooth BluetoothGattCharacteristic FORMAT_UINT32.
Click Source Link
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuService.java
/** * Writes the image size to the characteristic. This method is SYNCHRONOUS and wait until the {@link BluetoothGattCallback#onCharacteristicWrite(BluetoothGatt, BluetoothGattCharacteristic, int)} * will be called or the connection state will change from {@link #STATE_CONNECTED_AND_READY}. If connection state will change, or an error will occur, an exception will be thrown. * //from w ww . ja v a 2 s . c o m * @param gatt * the GATT device * @param characteristic * the characteristic to write to. Should be the DFU PACKET * @param imageSize * the image size in bytes * @throws DeviceDisconnectedException * @throws DfuException * @throws UploadAbortedException */ private void writeImageSize(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int imageSize) throws DeviceDisconnectedException, DfuException, UploadAbortedException { mReceivedData = null; mErrorState = 0; mImageSizeSent = false; characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); characteristic.setValue(imageSize, BluetoothGattCharacteristic.FORMAT_UINT32, 0); gatt.writeCharacteristic(characteristic); // We have to wait for confirmation try { synchronized (mLock) { while ((mImageSizeSent == false && mConnectionState == STATE_CONNECTED_AND_READY && mErrorState == 0 && !mAborted) || mPaused) mLock.wait(); } } catch (final InterruptedException e) { loge("Sleeping interrupted", e); } if (mAborted) throw new UploadAbortedException(); if (mErrorState != 0) throw new DfuException("Unable to write Image Size", mErrorState); if (mConnectionState != STATE_CONNECTED_AND_READY) throw new DeviceDisconnectedException("Unable to write Image Size", mConnectionState); }