List of usage examples for android.bluetooth BluetoothGattCharacteristic getValue
public byte[] getValue()
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 {/* w w w .j ava2 s. co m*/ return super.onCharacteristicChanged(gatt, characteristic); } }
From source file:io.v.android.libs.discovery.ble.BlePlugin.java
public BlePlugin(Context androidContext) { this.androidContext = androidContext; cachedDevices = new DeviceCache(Duration.standardMinutes(1)); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { return;//from w w w . j a v a2 s . c o m } if (!hasPermission(Manifest.permission.ACCESS_COARSE_LOCATION) && !hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)) { return; } isEnabled = true; bluetoothLeAdvertise = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser(); bluetoothLeScanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner(); BluetoothManager manager = (BluetoothManager) androidContext.getSystemService(Context.BLUETOOTH_SERVICE); bluetoothGattServer = manager.openGattServer(androidContext, new BluetoothGattServerCallback() { @Override public void onConnectionStateChange(BluetoothDevice device, int status, int newState) { super.onConnectionStateChange(device, status, newState); } @Override public void onCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic) { super.onCharacteristicReadRequest(device, requestId, offset, characteristic); byte[] total = characteristic.getValue(); byte[] res = {}; // Only send MTU - 1 bytes. The first byte of all packets is the op code. if (offset < total.length) { int finalByte = offset + MTU - 1; if (finalByte > total.length) { finalByte = total.length; } res = Arrays.copyOfRange(total, offset, finalByte); bluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, res); } else { // This should probably be an error, but a bug in the paypal/gatt code causes an // infinite loop if this returns an error rather than the empty value. bluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, res); } } }); }
From source file:com.huiwu.temperaturecontrol.bluetooth.BluetoothService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); if (TX_CHAR_UUID.equals(characteristic.getUuid())) { intent.putExtra(EXTRA_DATA, characteristic.getValue()); } else {/*from w ww . j av a 2s .c o m*/ } LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:io.v.android.impl.google.discovery.plugins.ble.Driver.java
public void onGattRead(BluetoothDevice device, BluetoothGattService service) { Map<String, byte[]> characteristics; ImmutableMap.Builder<String, byte[]> builder = new ImmutableMap.Builder(); for (BluetoothGattCharacteristic c : service.getCharacteristics()) { builder.put(c.getUuid().toString(), c.getValue()); }/* w w w .j a v a 2 s. c o m*/ characteristics = builder.build(); synchronized (this) { if (mScanSeens == null) { return; } Integer rssi = mScanSeens.get(device); if (rssi == null) { return; } mScanHandler.onDiscovered(service.getUuid().toString(), characteristics, rssi); mOnServiceReadCallbacks++; } }
From source file:com.example.android.alertbuddy.BluetoothLeService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); UUID uuid = characteristic.getUuid(); final byte[] data = characteristic.getValue(); if (uuid.equals(RX_UUID)) { if (data != null && data.length > 0) { intent.putExtra(EXTRA_DATA, data); }/*from www . jav a2 s .co m*/ } sendBroadcast(intent); }
From source file:com.ec.android.module.bluetooth40.BluetoothLeService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); ///*from w w w . j a v a 2 s . c om*/ if (SampleGattAttributes.NOTIFY_CHARACTERISTIC_CONFIG.equals(characteristic.getUuid().toString())) { final byte[] data = characteristic.getValue(); if (data != null && data.length > 0) { intent.putExtra(EXTRA_DATA, data); } } // mLocalBroadcastManager.sendBroadcast(intent); }
From source file:com.lannbox.rfduinotest.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); Log.w(TAG, "BTLE Data received and broadcasted"); // Create notification Intent notificationIntent = new Intent(RFduinoService.this, MainActivity.class); notificationIntent.setAction("RFduinoTest_CallToMain"); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(RFduinoService.this, 0, notificationIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(RFduinoService.this) .setContentTitle("Bluetooth Data").setTicker("New Bluetooth Data Received") .setContentText("Data:" + HexAsciiHelper.bytesToAsciiMaybe(characteristic.getValue()) + "\nOr: " + HexAsciiHelper.bytesToHex(characteristic.getValue())) .setSmallIcon(R.drawable.ic_launcher) // .setLargeIcon( // Bitmap.createScaledBitmap(icon, 128, 128, false)) .setAutoCancel(true).setContentIntent(pendingIntent); mNotificationManager.notify(110, mBuilder.build()); }/* ww w.j ava 2s .c o m*/ }
From source file:com.jordanfitzgibbon.rfduinohrm.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); Log.w(TAG, "BTLE Data received and broadcasted"); // Create notification Intent notificationIntent = new Intent(RFduinoService.this, com.jordanfitzgibbon.rfduinohrm.MainActivity.class); notificationIntent.setAction("RFduinoTest_CallToMain"); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(RFduinoService.this, 0, notificationIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(RFduinoService.this) .setContentTitle("Bluetooth Data").setTicker("New Bluetooth Data Received") .setContentText("Data:" + characteristic.getValue() + "\nOr: " + characteristic.getValue()) //.setContentText("Data:" + HexAsciiHelper.bytesToAsciiMaybe(characteristic.getValue()) + "\nOr: " + HexAsciiHelper.bytesToHex(characteristic.getValue())) //.setSmallIcon(R.drawable.ic_launcher) // .setLargeIcon( // Bitmap.createScaledBitmap(icon, 128, 128, false)) .setAutoCancel(true).setContentIntent(pendingIntent); mNotificationManager.notify(110, mBuilder.build()); }//from w w w.ja v a 2s . c om }
From source file:com.cqupt.sensor_ble.activity.UartService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); if (TX_CHAR_UUID.equals(characteristic.getUuid())) { final byte[] byte_data = characteristic.getValue(); if (byte_data != null && byte_data.length > 0) { final StringBuilder stringBuilder = new StringBuilder(byte_data.length); for (byte byteChar : byte_data) { stringBuilder.append(String.format("%X", byteChar)); }//from w w w. j ava 2s . c o m temp.append(stringBuilder.toString()).append(" "); if ("A".equals(stringBuilder.toString())) { //? String string = temp.toString(); if (string.length() == 34) { //?? String t = String.valueOf(string.charAt(7)) + String.valueOf(string.charAt(10)); //?? String h = String.valueOf(string.charAt(25)) + String.valueOf(string.charAt(28));//?? int[] int_array = new int[2]; int_array[0] = Integer.parseInt(h); int_array[1] = Integer.parseInt(t); intent.putExtra(EXTRA_DATA, int_array); } temp = null; temp = new StringBuilder(38); } } } else if (RX_CHAR_UUID.equals(characteristic.getUuid())) { intent.putExtra(CHAR1_DATA, "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0)); } else if (Battery_Level_UUID.equals(characteristic.getUuid())) { intent.putExtra(EXTRA_DATA, "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0)); } LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:com.example.bluetoothmodule.TreadmillService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); intent.putExtra(EXTRA_DATA, characteristic.getValue()); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }