|
|
@ -63,8 +63,10 @@ public class BluetoothLeService extends Service { |
|
|
public final static String EXTRA_DATA = |
|
|
public final static String EXTRA_DATA = |
|
|
"com.example.bluetooth.le.EXTRA_DATA"; |
|
|
"com.example.bluetooth.le.EXTRA_DATA"; |
|
|
|
|
|
|
|
|
|
|
|
/* TODO |
|
|
public final static UUID UUID_HEART_RATE_MEASUREMENT = |
|
|
public final static UUID UUID_HEART_RATE_MEASUREMENT = |
|
|
UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT); |
|
|
UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT); |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
// Implements callback methods for GATT events that the app cares about. For example,
|
|
|
// Implements callback methods for GATT events that the app cares about. For example,
|
|
|
// connection change and services discovered.
|
|
|
// connection change and services discovered.
|
|
|
@ -123,6 +125,7 @@ public class BluetoothLeService extends Service { |
|
|
final BluetoothGattCharacteristic characteristic) { |
|
|
final BluetoothGattCharacteristic characteristic) { |
|
|
final Intent intent = new Intent(action); |
|
|
final Intent intent = new Intent(action); |
|
|
|
|
|
|
|
|
|
|
|
/* TODO |
|
|
// This is special handling for the Heart Rate Measurement profile. Data parsing is
|
|
|
// This is special handling for the Heart Rate Measurement profile. Data parsing is
|
|
|
// carried out as per profile specifications:
|
|
|
// carried out as per profile specifications:
|
|
|
// http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
|
|
|
// http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
|
|
|
@ -140,6 +143,7 @@ public class BluetoothLeService extends Service { |
|
|
Log.d(TAG, String.format("Received heart rate: %d", heartRate)); |
|
|
Log.d(TAG, String.format("Received heart rate: %d", heartRate)); |
|
|
intent.putExtra(EXTRA_DATA, String.valueOf(heartRate)); |
|
|
intent.putExtra(EXTRA_DATA, String.valueOf(heartRate)); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
*/ |
|
|
// For all other profiles, writes the data formatted in HEX.
|
|
|
// For all other profiles, writes the data formatted in HEX.
|
|
|
final byte[] data = characteristic.getValue(); |
|
|
final byte[] data = characteristic.getValue(); |
|
|
if (data != null && data.length > 0) { |
|
|
if (data != null && data.length > 0) { |
|
|
@ -148,7 +152,9 @@ public class BluetoothLeService extends Service { |
|
|
stringBuilder.append(String.format("%02X ", byteChar)); |
|
|
stringBuilder.append(String.format("%02X ", byteChar)); |
|
|
intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString()); |
|
|
intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString()); |
|
|
} |
|
|
} |
|
|
|
|
|
/* TODO |
|
|
} |
|
|
} |
|
|
|
|
|
*/ |
|
|
sendBroadcast(intent); |
|
|
sendBroadcast(intent); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -296,6 +302,7 @@ public class BluetoothLeService extends Service { |
|
|
} |
|
|
} |
|
|
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); |
|
|
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); |
|
|
|
|
|
|
|
|
|
|
|
/* TODO |
|
|
// This is specific to Heart Rate Measurement.
|
|
|
// This is specific to Heart Rate Measurement.
|
|
|
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { |
|
|
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { |
|
|
BluetoothGattDescriptor descriptor = characteristic.getDescriptor( |
|
|
BluetoothGattDescriptor descriptor = characteristic.getDescriptor( |
|
|
@ -303,6 +310,7 @@ public class BluetoothLeService extends Service { |
|
|
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); |
|
|
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); |
|
|
mBluetoothGatt.writeDescriptor(descriptor); |
|
|
mBluetoothGatt.writeDescriptor(descriptor); |
|
|
} |
|
|
} |
|
|
|
|
|
*/ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|