本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.getValue方法的具體用法?Java BluetoothGattCharacteristic.getValue怎麽用?Java BluetoothGattCharacteristic.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothGattCharacteristic
的用法示例。
在下文中一共展示了BluetoothGattCharacteristic.getValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
final byte[] data = characteristic.getValue();
if(data == null)
return "";
final int length = data.length;
if(length == 0)
return "";
final char[] out = new char[length * 3 - 1];
for(int j = 0; j < length; j++) {
int v = data[j] & 0xFF;
out[j * 3] = HEX_ARRAY[v >>> 4];
out[j * 3 + 1] = HEX_ARRAY[v & 0x0F];
if(j != length - 1)
out[j * 3 + 2] = '-';
}
return new String(out);
}
示例2: onCharacteristicChanged
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
Log.d(mTAG, "onCharacteristicChanged");
byte[] mValue = characteristic.getValue();
if(characteristic.getUuid().equals(UUID_nRF51822_GET_TEMP)){
mAirTemperature = (mValue[0] << 8 | mValue[1])/10;
gatt.setCharacteristicNotification(characteristic, false);
List<BluetoothGattCharacteristic> lstChars = mGattnRF51822Service.getCharacteristics();
for(BluetoothGattCharacteristic mCharacteristic : lstChars){
List<BluetoothGattDescriptor> descriptors = mCharacteristic.getDescriptors();
BluetoothGattDescriptor mGattnRF51822Descriptor = mCharacteristic.getDescriptor(UUID_nRF51822_DESCRIPTOR_ID);
if(mGattnRF51822Descriptor != null && mCharacteristic.getUuid().equals(UUID_nRF51822_GET_LIGHT)){
gatt.setCharacteristicNotification(mCharacteristic, true);
byte[] mDesValue = {0x01, 0x00};
mGattnRF51822Descriptor.setValue(mDesValue);
gatt.writeDescriptor(mGattnRF51822Descriptor);
}
}
}
else if(characteristic.getUuid().equals(UUID_nRF51822_GET_LIGHT)){
mLight = (mValue[0] << 8 | mValue[1]);
gatt.close();
Log.d(mTAG, "onCharacteristicChanged data=" + getData());
mIsConnecting = false;
}
}
示例3: onCharacteristicRead
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicRead(gatt, characteristic, status);
Log.d(LOG_TAG, "onCharacteristicRead " + characteristic);
if (readCallback != null) {
if (status == BluetoothGatt.GATT_SUCCESS) {
byte[] dataValue = characteristic.getValue();
String value = BleManager.bytesToHex(dataValue);
if (readCallback != null) {
readCallback.invoke(null, value);
}
} else {
readCallback.invoke("Error reading " + characteristic.getUuid() + " status=" + status, null);
}
readCallback = null;
}
}
示例4: parse
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
static String parse(final BluetoothGattCharacteristic characteristic, final int offset) {
final int type = characteristic.getValue()[offset];
switch (type) {
case 1:
return "Armpit";
case 2:
return "Body (general)";
case 3:
return "Ear (usually ear lobe)";
case 4:
return "Finger";
case 5:
return "Gastro-intestinal Tract";
case 6:
return "Mouth";
case 7:
return "Rectum";
case 8:
return "Toe";
case 9:
return "Tympanum (ear drum)";
default:
return "Unknown";
}
}
示例5: onCharacteristicChanged
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
* 相當於一個監聽器, 當藍牙設備有數據返回時執行
*
* @param gatt
* @param characteristic
*/
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
Log.e(TAG, "onCharacteristicChanged 返回數據: " + Arrays.toString(characteristic.getValue()));
Message message = new Message();
message.what = Constant.RESULT_DATA;
message.obj = characteristic.getValue();
handler.sendMessage(message);
//回調
onCharacteristicRefresh(gatt, characteristic);
}
示例6: broadcastUpdate
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
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 (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
int flag = characteristic.getProperties();
int format = -1;
if ((flag & 0x01) != 0) {
format = BluetoothGattCharacteristic.FORMAT_UINT16;
Log.d(TAG, "Heart rate format UINT16.");
} else {
format = BluetoothGattCharacteristic.FORMAT_UINT8;
Log.d(TAG, "Heart rate format UINT8.");
}
final int heartRate = characteristic.getIntValue(format, 1);
Log.d(TAG, String.format("Received heart rate: %d", heartRate));
intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));
} 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);
}
示例7: m14598a
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static float m14598a(BluetoothGattCharacteristic bluetoothGattCharacteristic) {
byte[] value = bluetoothGattCharacteristic.getValue();
if (value == null || value.length != 2) {
return 0.0f;
}
return (float) ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).getChar();
}
示例8: onCharacteristicRead
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
// Result of a characteristic read operation
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
int status) {
resetConnectionTimeoutChecker();
if (status == BluetoothGatt.GATT_SUCCESS) {
Log.w("BLE", "CharacteristicRead - characteristics uuid: " + characteristic.getUuid());
Log.w("BLE", "CharacteristicRead - service uuid: " + characteristic.getService().getUuid());
Log.w("BLE", "CharacteristicRead - string value: " + characteristic.getValue());
byte[] bytes = characteristic.getValue();
for(byte b : bytes){
Log.w("BLE", "CharacteristicRead - byte value: " + b);
}
if(Globals.SNACH_SYSTEM_UART_TX_UUID.equals(characteristic.getUuid())){
Log.w("BLE", "CharacteristicRead - xaccel service uuid: " + characteristic.getService().getUuid());
Log.w("BLE", "CharacteristicRead - xaccel value: " + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16,0));
Log.w("BLE", "CharacteristicRead - xaccel value: " + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8,0));
Log.w("BLE", "CharacteristicRead - xaccel value: " + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8,1));
// setNotifySensor(gatt);
}
}
}
示例9: onCharacteristicRead
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
if(status == BluetoothGatt.GATT_SUCCESS){
if(characteristic.getUuid().equals(UUID_TITAG_GET_BATTERY)){
byte[] mValue = characteristic.getValue();
int mBattery = new Byte(mValue[0]).intValue();
setBattery(mBattery);
byte[] mHumidityValue = {mValue[0]};
mGattnTitagTempHumidityService.getCharacteristic(UUID_TITAG_ENABLE_AIR_TEMP_HUMIDITY).setValue(mHumidityValue);
gatt.writeCharacteristic(mGattnTitagTempHumidityService.getCharacteristic(UUID_TITAG_ENABLE_AIR_TEMP_HUMIDITY));
}
}
}
示例10: registerMicrobitRequirements
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
* Register to know about the micro:bit requirements. What events does the micro:bit need from us
* read repeatedly from (3) to find out the events that the micro:bit is interested in receiving.
* e.g. if a kids app registers to receive events <10,3><15,2> then the first read will
* give you <10,3> the second <15,2>, the third will give you a zero length value.
* You can send events to the micro:bit that haven't been asked for, but as no-one will
* be listening, they will be silently dropped.
*
* @param eventService Bluetooth GATT service.
* @param enable Enable or disable.
* @return True, if successful.
*/
private boolean registerMicrobitRequirements(BluetoothGattService eventService, boolean enable) {
BluetoothGattCharacteristic microbit_requirements = eventService.getCharacteristic(CharacteristicUUIDs
.ES_MICROBIT_REQUIREMENTS);
if(microbit_requirements == null) {
logi("register_eventsFromMicrobit() :: ES_MICROBIT_REQUIREMENTS Not found");
return false;
}
BluetoothGattDescriptor microbit_requirementsDescriptor = microbit_requirements.getDescriptor(UUIDs
.CLIENT_DESCRIPTOR);
if(microbit_requirementsDescriptor == null) {
logi("register_eventsFromMicrobit() :: CLIENT_DESCRIPTOR Not found");
return false;
}
BluetoothGattCharacteristic characteristic = readCharacteristic(microbit_requirements);
while(characteristic != null && characteristic.getValue() != null && characteristic.getValue().length != 0) {
String service = BluetoothUtils.parse(characteristic);
logi("microbit interested in = " + service);
if(service.equalsIgnoreCase("4F-04-07-00")) //Incoming Call service
{
sendMicroBitNeedsCallNotification();
}
if(service.equalsIgnoreCase("4F-04-08-00")) //Incoming SMS service
{
sendMicroBitNeedsSmsNotification();
}
characteristic = readCharacteristic(microbit_requirements);
}
registerForSignalStrength(enable);
registerForDeviceInfo(enable);
logi("registerMicrobitRequirements() :: found Constants.ES_MICROBIT_REQUIREMENTS ");
enableCharacteristicNotification(microbit_requirements, microbit_requirementsDescriptor, enable);
return true;
}
示例11: broadcastUpdate
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
final Intent intent = new Intent(action);
intent.putExtra(EXTRA_CHARACTERISTIC_UUID, characteristic.getUuid().toString());
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(CLIENT_EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());
}
sendBroadcast(intent);
}
示例12: parse
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
int offset = 0;
final int flags = characteristic.getValue()[offset]; // 1 byte
offset += 1;
final boolean wheelRevPresent = (flags & WHEEL_REV_DATA_PRESENT) > 0;
final boolean crankRevPreset = (flags & CRANK_REV_DATA_PRESENT) > 0;
int wheelRevolutions = 0;
int lastWheelEventTime = 0;
if (wheelRevPresent) {
wheelRevolutions = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, offset);
offset += 4;
lastWheelEventTime = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset); // 1/1024 s
offset += 2;
}
int crankRevolutions = 0;
int lastCrankEventTime = 0;
if (crankRevPreset) {
crankRevolutions = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
offset += 2;
lastCrankEventTime = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
//offset += 2;
}
final StringBuilder builder = new StringBuilder();
if (wheelRevPresent) {
builder.append(String.format("Wheel rev: %d,\n", wheelRevolutions));
builder.append(String.format("Last wheel event time: %d ms,\n", lastWheelEventTime));
}
if (crankRevPreset) {
builder.append(String.format("Crank rev: %d,\n", crankRevolutions));
builder.append(String.format("Last crank event time: %d ms,\n", lastCrankEventTime));
}
builder.setLength(builder.length() - 2);
return builder.toString();
}
示例13: parse
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
int offset = 0;
final int flags = characteristic.getValue()[offset]; // 1 byte
offset += 1;
final boolean islmPresent = (flags & INSTANTANEOUS_STRIDE_LENGTH_PRESENT) > 0;
final boolean tdPreset = (flags & TOTAL_DISTANCE_PRESENT) > 0;
final boolean running = (flags & WALKING_OR_RUNNING_STATUS_BITS) > 0;
final boolean walking = !running;
final float instantaneousSpeed = (float) characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset) / 256.0f; // 1/256 m/s
offset += 2;
final int instantaneousCadence = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
offset += 1;
float instantaneousStrideLength = 0;
if (islmPresent) {
instantaneousStrideLength = (float) characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset) / 100.0f; // 1/100 m
offset += 2;
}
float totalDistance = 0;
if (tdPreset) {
totalDistance = (float) characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, offset) / 10.0f;
// offset += 4;
}
final StringBuilder builder = new StringBuilder();
builder.append(String.format("Speed: %.2f m/s, Cadence: %d RPM,\n", instantaneousSpeed, instantaneousCadence));
if (islmPresent)
builder.append(String.format("Instantaneous Stride Length: %.2f m,\n", instantaneousStrideLength));
if (tdPreset)
builder.append(String.format("Total Distance: %.1f m,\n", totalDistance));
if (walking)
builder.append("Status: WALKING");
else
builder.append("Status: RUNNING");
return builder.toString();
}
示例14: onCharacteristicNotified
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
public void onCharacteristicNotified(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
if (mLogSession != null)
Logger.a(mLogSession, CSCMeasurementParser.parse(characteristic));
// Decode the new data
int offset = 0;
final int flags = characteristic.getValue()[offset]; // 1 byte
offset += 1;
final boolean wheelRevPresent = (flags & WHEEL_REVOLUTIONS_DATA_PRESENT) > 0;
final boolean crankRevPreset = (flags & CRANK_REVOLUTION_DATA_PRESENT) > 0;
if (wheelRevPresent) {
final int wheelRevolutions = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, offset);
offset += 4;
final int lastWheelEventTime = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset); // 1/1024 s
offset += 2;
// Notify listener about the new measurement
mCallbacks.onWheelMeasurementReceived(wheelRevolutions, lastWheelEventTime);
}
if (crankRevPreset) {
final int crankRevolutions = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
offset += 2;
final int lastCrankEventTime = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
// offset += 2;
// Notify listener about the new measurement
mCallbacks.onCrankMeasurementReceived(crankRevolutions, lastCrankEventTime);
}
}
示例15: broadcastUpdate
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
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);
}