public class HealthDeviceManager extends Object
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).
HealthDevice.Builder.build()
registerDevice(HealthDevice)
The user's device that installed your application can meet many environments like:
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.
setSourceDevices()
HealthDataResolver.ReadRequest.Builder
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); } }
getAllDevices()
//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()); } }
HealthDeviceManager(HealthDataStore store)
boolean
changeCustomName(String uuid, String name)
List<HealthDevice>
HealthDevice
getDeviceBySeed(String seed)
getDeviceByUuid(String uuid)
List<String>
getDeviceUuidsByCustomName(String name)
getDeviceUuidsByGroup(int group)
getDeviceUuidsByManufacturer(String manufacturer)
getDeviceUuidsByModel(String model)
getLocalDevice()
String
registerDevice(HealthDevice device)
public HealthDeviceManager(HealthDataStore store)
store
public HealthDevice getLocalDevice()
IllegalStateException
public List<HealthDevice> getAllDevices()
public String registerDevice(HealthDevice device)
device
IllegalArgumentException
null
public HealthDevice getDeviceBySeed(String seed)
seed
public HealthDevice getDeviceByUuid(String uuid)
uuid
public List<String> getDeviceUuidsByGroup(int group)
group
HealthDevice.GROUP_UNKNOWN
HealthDevice.GROUP_MOBILE
HealthDevice.GROUP_EXTERNAL
HealthDevice.GROUP_COMPANION
public List<String> getDeviceUuidsByCustomName(String name)
name
public List<String> getDeviceUuidsByModel(String model)
model
public List<String> getDeviceUuidsByManufacturer(String manufacturer)
manufacturer
public boolean changeCustomName(String uuid, String name)
true
false