List of usage examples for android.bluetooth BluetoothGattCharacteristic getStringValue
public String getStringValue(int offset)
From source file:Main.java
/** * Returns the model number from the given characteristic * //from ww w. ja v a 2s. c o m * @param characteristic * @return model_name_string */ @SuppressLint("NewApi") public static String getModelNumberString(BluetoothGattCharacteristic characteristic) { String model_name_string = characteristic.getStringValue(0); return model_name_string; }
From source file:Main.java
/** * Returns the manufacture name from the given characteristic * /* www . j ava2 s . c o m*/ * @param characteristic * @return manfacture_name_string */ @SuppressLint("NewApi") public static String getManufacturerNameString(BluetoothGattCharacteristic characteristic) { String manfacture_name_string = characteristic.getStringValue(0); return manfacture_name_string; }
From source file:Main.java
/** * Returns the serial number from the given characteristic * /* ww w.j a va 2 s. c o m*/ * @param characteristic * @return serial_number_string */ @SuppressLint("NewApi") public static String getSerialNumberString(BluetoothGattCharacteristic characteristic) { String serial_number_string = characteristic.getStringValue(0); return serial_number_string; }
From source file:Main.java
/** * Returns the hardware number from the given characteristic * // w ww . j a va 2s . c o m * @param characteristic * @return hardware_revision_name_string */ @SuppressLint("NewApi") public static String getHardwareRevisionString(BluetoothGattCharacteristic characteristic) { String hardware_revision_name_string = characteristic.getStringValue(0); return hardware_revision_name_string; }
From source file:Main.java
/** * Returns the software revision number from the given characteristic * /*from w ww.ja v a2 s. c o m*/ * @param characteristic * @return hardware_revision_name_string */ @SuppressLint("NewApi") public static String getSoftwareRevisionString(BluetoothGattCharacteristic characteristic) { String hardware_revision_name_string = characteristic.getStringValue(0); return hardware_revision_name_string; }
From source file:Main.java
/** * Returns the Firmware number from the given characteristic * /*from www .j a va 2 s. c o m*/ * @param characteristic * @return hardware_revision_name_string */ @SuppressLint("NewApi") public static String getFirmwareRevisionString(BluetoothGattCharacteristic characteristic) { String firmware_revision_name_string = characteristic.getStringValue(0); return firmware_revision_name_string; }
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 av a 2 s . c o m } LocalBroadcastManager.getInstance(this).sendBroadcast(intent); // DA onDataReceived(characteristic.getStringValue(0)); }
From source file:com.wolkabout.hexiwear.service.BluetoothService.java
private void createGATT(final BluetoothDevice device) { bluetoothGatt = device.connectGatt(this, true, new BluetoothGattCallback() { @Override/*from w w w .ja va 2s . co m*/ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { isConnected = BluetoothProfile.STATE_CONNECTED == newState; if (isConnected) { Log.i(TAG, "GATT connected."); startForeground(442, getNotification(device)); gatt.discoverServices(); } else { Log.i(TAG, "GATT disconnected."); NotificationService_.intent(BluetoothService.this).stop(); notificationManager.notify(442, getNotification(device)); gatt.connect(); } final Intent connectionStateChanged = new Intent(CONNECTION_STATE_CHANGED); connectionStateChanged.putExtra(CONNECTION_STATE, isConnected); sendBroadcast(connectionStateChanged); } @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { Log.i(TAG, "Services discovered."); if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) { handleAuthenticationError(gatt); return; } discoverCharacteristics(gatt); } @Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { Log.i(TAG, "Characteristic written: " + status); if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) { handleAuthenticationError(gatt); return; } final byte command = characteristic.getValue()[0]; switch (command) { case WRITE_TIME: Log.i(TAG, "Time written."); final BluetoothGattCharacteristic batteryCharacteristic = readableCharacteristics .get(Characteristic.BATTERY.getUuid()); gatt.setCharacteristicNotification(batteryCharacteristic, true); for (BluetoothGattDescriptor descriptor : batteryCharacteristic.getDescriptors()) { if (descriptor.getUuid().toString().startsWith("00002904")) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); gatt.writeDescriptor(descriptor); } } break; case WRITE_NOTIFICATION: Log.i(TAG, "Notification sent."); if (notificationsQueue.isEmpty()) { Log.i(TAG, "Reading characteristics..."); readNextCharacteristics(gatt); } else { Log.i(TAG, "writing next notification..."); alertIn.setValue(notificationsQueue.poll()); gatt.writeCharacteristic(alertIn); } break; default: Log.w(TAG, "No such ALERT IN command: " + command); break; } } @Override public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { readCharacteristic(gatt, Characteristic.MANUFACTURER); } @Override public void onCharacteristicRead(BluetoothGatt gatt, final BluetoothGattCharacteristic gattCharacteristic, int status) { if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) { handleAuthenticationError(gatt); return; } final String characteristicUuid = gattCharacteristic.getUuid().toString(); final Characteristic characteristic = Characteristic.byUuid(characteristicUuid); switch (characteristic) { case MANUFACTURER: manufacturerInfo.manufacturer = gattCharacteristic.getStringValue(0); readCharacteristic(gatt, Characteristic.FW_REVISION); break; case FW_REVISION: manufacturerInfo.firmwareRevision = gattCharacteristic.getStringValue(0); readCharacteristic(gatt, Characteristic.MODE); break; default: Log.v(TAG, "Characteristic read: " + characteristic.name()); if (characteristic == Characteristic.MODE) { final Mode newMode = Mode.bySymbol(gattCharacteristic.getValue()[0]); if (mode != newMode) { onModeChanged(newMode); } } else { onBluetoothDataReceived(characteristic, gattCharacteristic.getValue()); } if (notificationsQueue.isEmpty()) { readNextCharacteristics(gatt); } else { alertIn.setValue(notificationsQueue.poll()); gatt.writeCharacteristic(alertIn); } break; } } @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic gattCharacteristic) { final String characteristicUuid = gattCharacteristic.getUuid().toString(); final Characteristic characteristic = Characteristic.byUuid(characteristicUuid); Log.d(TAG, "Characteristic changed: " + characteristic); if (characteristic == Characteristic.BATTERY) { onBluetoothDataReceived(Characteristic.BATTERY, gattCharacteristic.getValue()); } } }); }