private void displayGattServices(List<BluetoothGattService> gattServices){
if(gattServices == null) return;
String uuid = null;
for(BluetoothGattService gattService : gattServices){
uuid = gattService.getUuid().toString();
if(uuid.equalsIgnoreCase(BATTERY_SERVICE)){
String uuid_charas = null;
List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
for(BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics){
uuid_charas = gattCharacteristic.getUuid().toString();
if(uuid_charas.equalsIgnoreCase(BATTERY_CHARATERISTIC)){
final int charaProp = gattCharacteristic.getProperties();
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
if (mNotifyCharacteristic != null) {
mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, false);
mNotifyCharacteristic = null;
}
mBluetoothLeService.readCharacteristic(gattCharacteristic);
}
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
mNotifyCharacteristic = gattCharacteristic;
mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);
}
}
}
}
}
}
private void broadcastUpdate(String action,BluetoothGattCharacteristic characteristic){
final Intent intent = new Intent(action);
if(UUID_HEART_RATE_MEASUREMENT.equals(characteristic .getUuid())){
int flag = characteristic.getProperties();
int format = -1;
if((flag&0x01) != 0){
format = BluetoothGattCharacteristic.FORMAT_UINT16;
}else {
format = BluetoothGattCharacteristic.FORMAT_UINT8;
}
final int heartRate = characteristic.getIntValue(format,1);
intent.putExtra(EXTRA_DATA,String.valueOf(heartRate));
}else {
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);
}
读取到了电量的特征值,但是显示d 64,怎么让它解析成百分比的形式显示在text文本?求各位大侠拔刀相助!~