本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.FORMAT_SINT16屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.FORMAT_SINT16屬性的具體用法?Java BluetoothGattCharacteristic.FORMAT_SINT16怎麽用?Java BluetoothGattCharacteristic.FORMAT_SINT16使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.bluetooth.BluetoothGattCharacteristic
的用法示例。
在下文中一共展示了BluetoothGattCharacteristic.FORMAT_SINT16屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: broadcastUpdate
private void broadcastUpdate(final String action,
final BluetoothGattCharacteristic characteristic) {
final Intent intent = new Intent(action);
// This is special handling for the Environmental Sensing profile. Data parsing is
// carried out as per profile specifications:
// http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml
if (IGrowGattAttributes.TEMPERATURE.equals(characteristic.getUuid())) {
int format = BluetoothGattCharacteristic.FORMAT_SINT16;
Log.d(TAG, "Temperature format SINT16.");
final int temperature = characteristic.getIntValue(format, 1);
Log.d(TAG, String.format("Received temperature: %d", temperature));
intent.putExtra(BluetoothLeService.EXTRA_DATA, String.valueOf(temperature));
} else {
// For all other profiles, writes the data formatted in HEX.
final byte[] data = characteristic.getValue();
if (data != null && data.length > 0) {
final StringBuilder stringBuilder = new StringBuilder(data.length);
for (byte byteChar : data)
stringBuilder.append(String.format("%02X ", byteChar));
intent.putExtra(BluetoothLeService.EXTRA_DATA, new String(data)
+ "\n" + stringBuilder.toString());
}
}
sendBroadcast(intent);
}
示例2: broadcastUpdate
private void broadcastUpdate(final String action,
final BluetoothGattCharacteristic characteristic) {
final Intent intent = new Intent(action);
// This is special handling for the Environmental Sensing profile. Data parsing is
// carried out as per profile specifications:
// http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml
if (IGrowGattAttributes.TEMPERATURE.equals(characteristic.getUuid())) {
int format = BluetoothGattCharacteristic.FORMAT_SINT16;
Log.d(TAG, "Temperature format SINT16.");
final int temperature = characteristic.getIntValue(format, 1);
Log.d(TAG, String.format("Received temperature: %d", temperature));
intent.putExtra(EXTRA_DATA, String.valueOf(temperature));
} else {
// For all other profiles, writes the data formatted in HEX.
final byte[] data = characteristic.getValue();
if (data != null && data.length > 0) {
final StringBuilder stringBuilder = new StringBuilder(data.length);
for(byte byteChar : data)
stringBuilder.append(String.format("%02X ", byteChar));
intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());
}
}
sendBroadcast(intent);
}