This class provides device information that is registered in the data framework and is able to register a new source
device that provides health data.
If a new data is saved to Samsung Health and its source device is new,
the source device is registered to the health data framework automatically.
A device with Samsung Health installed is recognized as the local device.
Registering a new source device separately is availble
with HealthDevice.Builder.build()
and registerDevice(HealthDevice)
.
The user's device that installed your application can meet many environments like:
- Changing a phone and synchronizing Samsung Health data with the user's Samsung account.
All data in the old phone are moved to the new one.
- Using an accessory such as Galaxy Watch with the phone.
A data query need to be requested with varied considerations for your application and target devices.
If you want to make that the query result contains only data your intended devices, set
data's source devices for the data query such as with
setSourceDevices()
of HealthDataResolver.ReadRequest.Builder
.
Otherwise, the query result can contain unintentional data of registered other accessories to Samsung Health.
Getting Current Device Information
The current device that
Samsung Health runs is registered as the local device in the health data framework.
If your application runs the current device and adds a new data to
Samsung Health,
set the data's source device as the local device.
The following example shows how to get the current device information.
public class HeathDataExample {
// The state of connection
private HealthDataStore mStore;
void createHealthData() {
HealthData data = new HealthData();
// Sets required properties
// Sets source device's UUID
data.setSourceDevice(new HealthDeviceManager(mStore).getLocalDevice().getUuid());
// Adds new data to Samsung Health
HealthDataResolver resolver = new HealthDataResolver(mStore, null);
InsertRequest request = new InsertRequest.Builder().setDataType(Nutrition.HEALTH_DATA_TYPE).build();
request.addHealthData(data);
}
}
Getting All Registered Devices' Information
Samsung Health works with accessories such as Galaxy Watch by the user's registration and can save
the registered accessory's health data.
Also your application can work with a linked accessory and inserts its measured data to
Samsung Health.
You can get all registered devices to
Samsung Health with
getAllDevices()
and figure out other devices beside the current device that
Samsung Health runs as the following
example.
//Gets the current device
HealthDeviceManager deviceManager = new HealthDeviceManager(mStore);
String localUuid = deviceManager.getLocalDevice().getUuid();
// Gets all registered devices
List<HealthDevice> healthDevices = new HealthDeviceManager(mStore).getAllDevices();
// Checks registered devices beside the current device
for (HealthDevice device : healthDevices) {
if (!device.getUuid().equals(localUuid)) {
Log.d(APP_TAG, "Accessory's UUID: " + device.getUuid());
}
}
Registering Device to Samsung Health
If you add data to
Samsung Health and the data's source device is not registered yet on
Samsung Health,
register the data's source device before to adding data with
registerDevice(HealthDevice)
.