Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void writeCustomCharacteristic(int value) {
- if (mBluetoothAdapter == null || mBluetoothGatt == null) {
- Log.w(TAG, "BluetoothAdapter not initialized");
- return;
- }
- /*check if the service is available on the device*/
- BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"));
- if(mCustomService == null){
- Log.w(TAG, "Custom BLE Service not found");
- return;
- }
- /*get the read characteristic from the service*/
- BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"));
- mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
- if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
- Log.w(TAG, "Failed to write characteristic");
- }
- }
- Below is my activity code:
- public void onClickWrite(View v){
- if(mBluetoothLeService != null) {
- mBluetoothLeService.writeCustomCharacteristic(0x666666);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment