List of usage examples for android.bluetooth BluetoothGattCharacteristic getUuid
public UUID getUuid()
From source file:Main.java
public static BluetoothGattCharacteristic findCharacteristic(UUID uuid, List<BluetoothGattCharacteristic> gattCharacteristics) { if (gattCharacteristics != null && gattCharacteristics.size() > 0) { for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { if (gattCharacteristic != null) { if (gattCharacteristic.getUuid().equals(uuid)) { return gattCharacteristic; }/*from ww w . j a v a2 s . c om*/ } } } return null; }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.InitOperation.java
@Override public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { UUID characteristicUUID = characteristic.getUuid(); if (MiBand2Service.UUID_CHARACTERISTIC_AUTH.equals(characteristicUUID)) { try {//from ww w. ja v a2 s. c o m byte[] value = characteristic.getValue(); getSupport().logMessageContent(value); if (value[0] == MiBand2Service.AUTH_RESPONSE && value[1] == MiBand2Service.AUTH_SEND_KEY && value[2] == MiBand2Service.AUTH_SUCCESS) { TransactionBuilder builder = createTransactionBuilder("Sending the secret key to the band"); builder.write(characteristic, requestAuthNumber()); getSupport().performImmediately(builder); } else if (value[0] == MiBand2Service.AUTH_RESPONSE && value[1] == MiBand2Service.AUTH_REQUEST_RANDOM_AUTH_NUMBER && value[2] == MiBand2Service.AUTH_SUCCESS) { // md5?? byte[] eValue = handleAESAuth(value, getSecretKey()); byte[] responseValue = org.apache.commons.lang3.ArrayUtils.addAll( new byte[] { MiBand2Service.AUTH_SEND_ENCRYPTED_AUTH_NUMBER, MiBand2Service.AUTH_BYTE }, eValue); TransactionBuilder builder = createTransactionBuilder( "Sending the encrypted random key to the band"); builder.write(characteristic, responseValue); getSupport().setCurrentTimeWithService(builder); getSupport().performImmediately(builder); } else if (value[0] == MiBand2Service.AUTH_RESPONSE && value[1] == MiBand2Service.AUTH_SEND_ENCRYPTED_AUTH_NUMBER && value[2] == MiBand2Service.AUTH_SUCCESS) { TransactionBuilder builder = createTransactionBuilder("Authenticated, now initialize phase 2"); builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext())); getSupport().requestDeviceInfo(builder); getSupport().phase2Initialize(builder); getSupport().setInitialized(builder); getSupport().performImmediately(builder); } else { return super.onCharacteristicChanged(gatt, characteristic); } } catch (Exception e) { GB.toast(getContext(), "Error authenticating Mi Band 2", Toast.LENGTH_LONG, GB.ERROR, e); } return true; } else { LOG.info("Unhandled characteristic changed: " + characteristicUUID); return super.onCharacteristicChanged(gatt, characteristic); } }
From source file:com.megster.cordova.rfduino.Peripheral.java
@Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { super.onCharacteristicChanged(gatt, characteristic); if (characteristic.getUuid().equals(RECEIVE_CHARACTERISTIC_UUID)) { PluginResult result = new PluginResult(PluginResult.Status.OK, characteristic.getValue()); result.setKeepCallback(true);/*from w w w. j a va 2s .c om*/ onDataCallback.sendPluginResult(result); } }
From source file:com.cypress.cysmart.BLEServiceFragments.GlucoseService.java
/** * Method to get required characteristics from service *//* w w w.j av a 2s .com*/ void getGattData() { List<BluetoothGattCharacteristic> gattCharacteristics = mservice.getCharacteristics(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.GLUCOSE_COCNTRN)) { mNotifyCharacteristic = gattCharacteristic; prepareBroadcastDataNotify(mNotifyCharacteristic); } } }
From source file:com.orange.beaconme_sdk.ble.control.BeaconTagDeviceUpdater.java
private void onReadCharacteristic(BluetoothGattCharacteristic characteristic, BluetoothGatt gatt, int status) { Log.i("Updater", "onReadCharacteristic"); UUID charUUID = characteristic.getUuid(); for (WriteCharacteristicCommand command : commands) { if (command.getCharacteristicUUID().equals(charUUID)) { if (characteristic.getValue() == null) { Log.e(TAG, String.format("read characteristic %s value=%s, status=%d", characteristic.getUuid(), Arrays.toString(characteristic.getValue()), status)); } else { byte[] newValue; if (command.getSwitchState() != WriteCharacteristicCommand.SwitchState.NONE) { newValue = getEnablingValueForChar(characteristic, command.getSwitchState() == WriteCharacteristicCommand.SwitchState.ENABLE); } else { newValue = command.getBytesToUpload(); }//from w ww . j a v a2 s . c om if (!Arrays.equals(characteristic.getValue(), newValue)) { characteristic.setValue(newValue); queue(getWriteCharacteristicOperation(characteristic)); } else { doneUploadingUuid(characteristic.getUuid()); } } } } }
From source file:com.orange.beaconme_sdk.ble.control.BeaconTagDeviceUpdater.java
private byte[] getEnablingValueForChar(BluetoothGattCharacteristic characteristic, boolean enable) { byte[] newValue = Arrays.copyOf(characteristic.getValue(), characteristic.getValue().length); if (characteristic.getUuid().equals(BeaconTagDevice.SLEEP_CHARACTERISTIC_UUID)) { newValue[0] = 0;//from www. j a v a 2 s . c o m newValue[1] = 0; } else { newValue[0] = (byte) (enable ? 1 : 0); } return newValue; }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation.java
@Override public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { UUID characteristicUUID = characteristic.getUuid(); if (MiBand2Service.UUID_CHARACTERISTIC_5_ACTIVITY_DATA.equals(characteristicUUID)) { handleActivityNotif(characteristic.getValue()); return true; } else if (MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC4.equals(characteristicUUID)) { handleActivityMetadata(characteristic.getValue()); return true; } else {/*from w ww .j a v a2s. c om*/ return super.onCharacteristicChanged(gatt, characteristic); } }
From source file:com.cypress.cysmart.BLEServiceFragments.BloodPressureService.java
/** * Method to get required characteristics from service *//*from ww w . java2 s .c om*/ void getGattData() { List<BluetoothGattCharacteristic> gattCharacteristics = mService.getCharacteristics(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.BLOOD_PRESSURE_MEASUREMENT)) { mIndicateCharacteristic = gattCharacteristic; prepareBroadcastDataIndicate(gattCharacteristic); break; } } }
From source file:com.cypress.cysmart.BLEServiceFragments.BatteryInformationService.java
/** * Method to get required characteristics from service *//*from ww w .j ava2 s . co m*/ void getGattData() { List<BluetoothGattCharacteristic> gattCharacteristics = mService.getCharacteristics(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.BATTERY_LEVEL)) { mReadCharacteristic = gattCharacteristic; mNotifyCharacteristic = gattCharacteristic; /** * Checking the various GattCharacteristics and listing in the ListView */ if (checkCharacteristicsPropertyPresence(gattCharacteristic.getProperties(), BluetoothGattCharacteristic.PROPERTY_READ)) { mReadButton.setVisibility(View.VISIBLE); } if (checkCharacteristicsPropertyPresence(gattCharacteristic.getProperties(), BluetoothGattCharacteristic.PROPERTY_NOTIFY)) { mNotifyButton.setVisibility(View.VISIBLE); } prepareBroadcastDataRead(gattCharacteristic); break; } } }
From source file:com.example.emulator.EmulatorFragment.java
@Override public void notificationsDisabled(BluetoothGattCharacteristic characteristic) { if (characteristic.getUuid() != BATTERY_LEVEL_UUID) { return;//from ww w . j a v a2s . co m } getActivity().runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getActivity(), R.string.notificationsNotEnabled, Toast.LENGTH_SHORT).show(); } }); mDemoPractice.execute(); }