List of usage examples for android.bluetooth BluetoothGattCharacteristic getValue
public byte[] getValue()
From source file:com.example.bluetooth.RFduinoService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { if (UUID_RECEIVE.equals(characteristic.getUuid())) { final Intent intent = new Intent(action); intent.putExtra(EXTRA_DATA, characteristic.getValue()); //sendBroadcast(intent, Manifest.permission.BLUETOOTH); // Left it, to avoid modify BluetoothActivty due to time constraints mServiceStart = true;//www. j a v a 2 s . c o m intent.putExtra(ACTION_DATA_TAG, true); sendOrderedBroadcast(intent, Manifest.permission.BLUETOOTH, new BroadcastReceiver() { @Override public void onReceive(Context pContext, Intent pIntent) { //String pResultData = getResultData(); if (getResultData() != null && getResultData().equals("Tag_Activity")) { mServiceStart = false; Log.wtf(TAG, "StartService false"); } // Trigger Reminder Service if (mServiceStart) { final Intent mReminderIntent = new Intent(getApplicationContext(), ReminderService.class); mReminderIntent.putExtra(ACTION_DATA_SERVICE, true); mReminderIntent.putExtra(EXTRA_DATA, characteristic.getValue()); getApplicationContext().startService(mReminderIntent); } } }, null, Activity.RESULT_OK, null, null); Log.w(TAG, "BTLE Data received and Broadcasted"); // // Trigger Reminder Service // if(mServiceStart) { // final Intent mReminderIntent = new Intent(getApplicationContext(), ReminderService.class); // mReminderIntent.putExtra(ACTION_DATA_SERVICE, true); // mReminderIntent.putExtra(EXTRA_DATA, characteristic.getValue()); // getApplicationContext().startService(mReminderIntent); // } } }
From source file:com.nordicsemi.UART_UDP_PROXY.UartService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); if (TX_CHAR_UUID.equals(characteristic.getUuid())) { // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() )); intent.putExtra(EXTRA_DATA, characteristic.getValue()); } else {/*w w w . j a v a 2s. co m*/ } LocalBroadcastManager.getInstance(this).sendBroadcast(intent); // DA onDataReceived(characteristic.getStringValue(0)); }
From source file:com.google.android.apps.forscience.ble.MyBleService.java
public void printServices(String address) { BluetoothGatt bluetoothGatt = addressToGattClient.get(address); if (bluetoothGatt == null) { Log.d(TAG, "No connection found for: " + address); return;/*from w w w . j av a2s .c o m*/ } for (BluetoothGattService service : bluetoothGatt.getServices()) { Log.d(TAG, "Service ================================"); Log.d(TAG, "Service UUID: " + service.getUuid()); Log.d(TAG, "Service Type: " + service.getType()); for (BluetoothGattCharacteristic charact : service.getCharacteristics()) { Log.d(TAG, "Charact UUID: " + charact.getUuid()); Log.d(TAG, "Charact prop: " + charact.getProperties()); if (charact.getValue() != null) { Log.d(TAG, "Charact Value: " + new String(charact.getValue())); } } } }
From source file:de.blinkt.openvpn.bluetooth.service.UartService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); if (TX_CHAR_UUID1.equals(characteristic.getUuid())) { byte[] txValue = characteristic.getValue(); int lengthData = (txValue[1] & 0x7f) + 1; int dataStatue = txValue[1] & 0x80; String messageFromBlueTooth = HexStringExchangeBytesUtil.bytesToHexString(characteristic.getValue()); Log.e("UartService", messageFromBlueTooth); if (lengthData == 1 && dataStatue == 0x80) { //TODO ?? // messages.add(messageFromBlueTooth); ArrayList<String> onePackagemessage = new ArrayList<>(); onePackagemessage.add(messageFromBlueTooth); intent.putStringArrayListExtra(EXTRA_DATA, onePackagemessage); LocalBroadcastManager.getInstance(ICSOpenVPNApplication.getContext()).sendBroadcast(intent); return; } else {// w w w. j a va 2s .com //TODO ? if (TextUtils.isEmpty(messageFromBlueTooth)) { return; } if (messages == null) { messages = new ArrayList<>(); } messages.add(messageFromBlueTooth); if (messages.size() < lengthData) { if (dataStatue == 0x80) { isWholeDataPackage = true; } return; } if (isWholeDataPackage || dataStatue == 0x80) { isWholeDataPackage = false; sortMessage(); intent.putStringArrayListExtra(EXTRA_DATA, messages); Log.e("UartService", messages.toString()); LocalBroadcastManager.getInstance(ICSOpenVPNApplication.getContext()).sendBroadcast(intent); } } // intent.putExtra(EXTRA_DATA, messageFromBlueTooth); // if(messages.size()==0){ // return; // } } }
From source file:com.vehicle.uart.UartService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); // This is special handling for the Heart Rate Measurement profile. Data parsing is // carried out as per profile specifications: // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml if (TX_CHAR_UUID.equals(characteristic.getUuid())) { intent.putExtra(EXTRA_DATA, characteristic.getValue()); } else {//from w ww .j ava2 s. c o m } LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.no1f1.No1F1Support.java
@Override public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { if (super.onCharacteristicChanged(gatt, characteristic)) { return true; }/* w w w . java 2 s . c om*/ UUID characteristicUUID = characteristic.getUuid(); byte[] data = characteristic.getValue(); if (data.length == 0) return true; switch (data[0]) { case No1F1Constants.CMD_FIRMWARE_VERSION: versionCmd.fwVersion = new String(Arrays.copyOfRange(data, 1, data.length)); handleGBDeviceEvent(versionCmd); LOG.info("Firmware version is: " + versionCmd.fwVersion); return true; case No1F1Constants.CMD_BATTERY: batteryCmd.level = data[1]; handleGBDeviceEvent(batteryCmd); LOG.info("Battery level is: " + data[1]); return true; case No1F1Constants.CMD_DATETIME: LOG.info("Time is set to: " + (data[1] * 256 + ((int) data[2] & 0xff)) + "-" + data[3] + "-" + data[4] + " " + data[5] + ":" + data[6] + ":" + data[7]); return true; case No1F1Constants.CMD_USER_DATA: LOG.info("User data updated"); return true; case No1F1Constants.CMD_FETCH_STEPS: case No1F1Constants.CMD_FETCH_SLEEP: case No1F1Constants.CMD_FETCH_HEARTRATE: handleActivityData(data); return true; case No1F1Constants.CMD_REALTIME_HEARTRATE: handleRealtimeHeartRateData(data); return true; case No1F1Constants.CMD_NOTIFICATION: case No1F1Constants.CMD_ICON: case No1F1Constants.CMD_DEVICE_SETTINGS: case No1F1Constants.CMD_DISPLAY_SETTINGS: return true; default: LOG.warn("Unhandled characteristic change: " + characteristicUUID + " code: " + Arrays.toString(data)); return true; } }
From source file:com.aprilbrother.blueduino.UartService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); // This is special handling for the Heart Rate Measurement profile. Data // parsing is // carried out as per profile specifications: // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml if (TX_CHAR_UUID.equals(characteristic.getUuid())) { intent.putExtra(EXTRA_DATA, characteristic.getValue()); } else {//w ww. j av a2 s . c o m } LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:com.megster.cordova.ble.central.Peripheral.java
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicRead(gatt, characteristic, status); LOG.d(TAG, "onCharacteristicRead " + characteristic); if (readCallback != null) { if (status == BluetoothGatt.GATT_SUCCESS) { readCallback.success(characteristic.getValue()); } else {/*from w ww. j a va 2s . c o m*/ readCallback.error("Error reading " + characteristic.getUuid() + " status=" + status); } readCallback = null; } commandCompleted(); }
From source file:org.physical_web.physicalweb.BluetoothSite.java
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { // Make sure the site is running. It can stop if the dialog is dismissed very quickly. if (!isRunning()) { close();//from w w w .j ava 2 s . c o m return; } // Make sure the read was successful. if (status != BluetoothGatt.GATT_SUCCESS) { Log.i(TAG, "onCharacteristicRead unsuccessful: " + status); close(); Toast.makeText(activity, R.string.ble_download_error_message, Toast.LENGTH_SHORT).show(); return; } // Record the data. Log.i(TAG, "onCharacteristicRead successful"); try { mHtml.write(characteristic.getValue()); } catch (IOException e) { Log.e(TAG, "Could not write to buffer", e); close(); return; } // Request a new read if we are not done. if (characteristic.getValue().length == transferRate) { gatt.readCharacteristic(this.characteristic); return; } // At this point we are done. Show the file. Log.i(TAG, "transfer is complete"); close(); openInChrome(getHtmlFile()); }
From source file:com.google.android.apps.forscience.ble.MyBleService.java
private void sendGattBroadcast(String address, String gattAction, BluetoothGattCharacteristic characteristic) { if (DEBUG)//from ww w . j a va2 s . co m Log.d(TAG, "Sending the action: " + gattAction); Intent newIntent = BleEvents.createIntent(gattAction, address); if (characteristic != null) { newIntent.putExtra(UUID, characteristic.getUuid().toString()); newIntent.putExtra(FLAGS, characteristic.getProperties()); newIntent.putExtra(DATA, characteristic.getValue()); } LocalBroadcastManager.getInstance(this).sendBroadcast(newIntent); }