HealthDataResolver
overview package class tree deprecated index com.samsung.android.sdk.healthdata class healthdataresolver java.lang.object com.samsung.android.sdk.healthdata.healthdataresolver public class healthdataresolver extends object this class is able to access health data to insert, read, update, and delete with the specified filter and some aggregate functions. data management health data can be accessed with following interfaces mainly. healthdataresolver.insertrequest healthdataresolver.readrequest healthdataresolver.updaterequest healthdataresolver.deleterequest healthdataresolver.aggregaterequest filter handling a part of data is a common use case rather than accessing whole data for the health data type. the health data framework provides a filter to specify the precise scope for health data and is able to access required data only. healthdataresolver.filter asynchronous data request the asynchronous request is used normally for operations that take a time such as reading data with conditions. if you need to request asynchronously, set the result listener with healthresultholder.setresultlistener(healthresultholder.resultlistener). the following example shows how to make an asynchronous request. public class healthdataresolverexample { // the state of connection healthdatastore mstore; public static final string app_tag = "myapp"; public void readglucoseasynchronously(long starttime, long endtime) { healthdataresolver resolver = new healthdataresolver(mstore, null); healthdataresolver.readrequest request = new healthdataresolver.readrequest.builder() .setdatatype(healthconstants.bloodglucose.health_data_type) .setlocaltimerange(healthconstants.bloodglucose.start_time, healthconstants.bloodglucose.time_offset, starttime, endtime) .build(); try { resolver.read(request).setresultlistener(mrdresult); } catch (exception e) { log.d(app_tag, "reading health data fails."); } } private final healthresultholder.resultlistener<healthdataresolver.readresult> mrdresult = new healthresultholder.resultlistener<healthdataresolver.readresult>(){ @override public void onresult(healthdataresolver.readresult result) { try { iterator<healthdata> iterator = result.iterator(); if (iterator.hasnext()) { healthdata data = iterator.next(); float glucosevalue = data.getfloat(healthconstants.bloodglucose.glucose); } finally { result.close(); } }; } synchronous datarequest though asynchronous data request is used commonly, there is a way to get the query result synchronously with healthresultholder.await(). note, not to make the synchronous request on the ui thread. healthresultholder.await() throws an exception if it is called on the main thread. it can hang your application caused by taking a time to handle the synchronous query. the following example shows how to make a synchronous request. public class healthdataresolverexample { // the state of connection healthdatastore mstore; public static final string app_tag = "myapp"; public void readglucosesynchronously(long starttime, long endtime) { healthdataresolver resolver = new healthdataresolver(mstore, null); healthdataresolver.readrequest request = new healthdataresolver.readrequest.builder() .setdatatype(healthconstants.bloodglucose.health_data_type) .setlocaltimerange(healthconstants.bloodglucose.start_time, healthconstants.bloodglucose.time_offset, starttime, endtime) .build(); try { // checks the result immediately healthdataresolver.readresult rdresult = resolver.read(request).await(); try { iterator<healthdata> iterator = rdresult.iterator(); if (iterator.hasnext()) { healthdata data = iterator.next(); float glucosevalue = data.getfloat(healthconstants.bloodglucose.glucose); } finally { rdresult.close(); } } catch (exception e) { log.d(app_tag, "reading health data fails."); } } } acquiring data permission getting data permission is required after connection to the health data store to synchronize health data with samsung health. samsung health sdk for android provides the data permission ui to get the user's consent. the user can agree to share health data with the application through the permission ui and the application can get required data permission check healthpermissionmanager to use the permission ui. if you try to read or write health data without permission, the sdk gives securityexception. acquiring instant data permission gaining the healthconstants.healthdocument type's permission is different with other data types. it is available by acquiring the instant permission. instant permission is created for one-time data access. it is proper to handle very sensitive health data. the data type needs the instant permission is healthconstants.healthdocument. an app needs the instant permission whenever it accesses health document data. healthdataresolver.insertwithpermission() healthdataresolver.readwithpermission() healthdataresolver.deletewithpermission() if you call healthdataresolver.readwithpermission(), its permission pop-up is shown. the user can select one or more health documents in the list and read the selected document. class relationship of healthdataresolver see a relationship of healthdataresolver with other classes. since: 1.0.0 nested class summary nested classes modifier and type class and description static interface healthdataresolver.aggregaterequest this interface represents an aggregate request with aggregate functions and the specified time unit to group result values. static class healthdataresolver.aggregateresult this class represents the result of healthdataresolver.aggregaterequest. static interface healthdataresolver.deleterequest this interface is able to make a request to delete health data for the specific health data type. static class healthdataresolver.filter this class creates a filter to make the request range clear. static interface healthdataresolver.insertrequest this interface is able to make a request to insert health data for the specific health data type. static interface healthdataresolver.readrequest this interface is able to make a request to read health data for the specific health data type. static class healthdataresolver.readresult this class represents the result for healthdataresolver.readrequest. static class healthdataresolver.sortorder this enum defines sort orders. static interface healthdataresolver.updaterequest this interface is able to make a request to update health data for the specific health data type. constructor summary constructors constructor and description healthdataresolver(healthdatastore store, handler handler) creates a healthdataresolver instance. method summary all methods instance methods concrete methods modifier and type method and description healthresultholder<healthdataresolver.aggregateresult> aggregate(healthdataresolver.aggregaterequest request) aggregates health data with the given request. healthresultholder<healthresultholder.baseresult> delete(healthdataresolver.deleterequest request) deletes health data with the given request. healthresultholder<healthresultholder.baseresult> deletewithpermission(healthdataresolver.deleterequest request, activity activity) deletes health data required instant permission with the given request. healthresultholder<healthresultholder.baseresult> insert(healthdataresolver.insertrequest request) inserts new health data with the given request. healthresultholder<healthresultholder.baseresult> insertwithpermission(healthdataresolver.insertrequest request, activity activity) inserts new health data required instant permission with the given request. healthresultholder<healthdataresolver.readresult> read(healthdataresolver.readrequest request) reads health data with the given request. healthresultholder<healthdataresolver.readresult> readwithpermission(healthdataresolver.readrequest request, activity activity) reads health data required instant permission with the given request. healthresultholder<healthresultholder.baseresult> update(healthdataresolver.updaterequest request) updates health data with the given request. constructor detail healthdataresolver public healthdataresolver(healthdatastore store, handler handler) creates a healthdataresolver instance. parameters: store - the health data store for connection handler - the handler for the proceeding thread. if it's null, the looper of the current thread will be used. since: 1.0.0 method detail insert public healthresultholder<healthresultholder.baseresult> insert(healthdataresolver.insertrequest request) inserts new health data with the given request. it can be implemented asynchronously or synchronously. check this request's result in healthresultholder.baseresult.getstatus(). parameters: request - the request to insert new health data returns: the healthresultholder instance which resolves to the healthresultholder.baseresult for inserted health data throws: illegalargumentexception - if the request contains invalid instance type or null. securityexception - if there is no permission to write for given health data illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs on the connection since: 1.0.0 insertwithpermission public healthresultholder<healthresultholder.baseresult> insertwithpermission(healthdataresolver.insertrequest request, activity activity) inserts new health data required instant permission with the given request. calling this method, a file chooser is shown to acquire the user consent. after the user chooses all or some of files, those are finally inserted. it can be implemented asynchronously or synchronously. check this request's result in healthresultholder.baseresult.getstatus(). parameters: request - the request to insert new health data activity - the activity that pop up the permission ui returns: the healthresultholder instance which resolves to the healthresultholder.baseresult for inserted health data throws: illegalargumentexception - if the request contains invalid instance typeor null. illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs on the connection since: 1.3.0 update public healthresultholder<healthresultholder.baseresult> update(healthdataresolver.updaterequest request) updates health data with the given request. it can be implemented asynchronously or synchronously. check this request's result through healthresultholder.baseresult.getstatus(). parameters: request - the request to update health data returns: the healthresultholder instance which resolves to the healthresultholder.baseresult for updated health data throws: illegalargumentexception - if the request contains invalid instance typeor null. securityexception - if there is no permission to write for given health data illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs on the connection since: 1.0.0 delete public healthresultholder<healthresultholder.baseresult> delete(healthdataresolver.deleterequest request) deletes health data with the given request. it can be implemented asynchronously or synchronously. parameters: request - the request to delete health data returns: the healthresultholder instance which resolves to the healthresultholder.baseresult for deleted health data throws: illegalargumentexception - if the request contains invalid instance type or null securityexception - if there is no permission to write for given health data illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs on the connection since: 1.0.0 deletewithpermission public healthresultholder<healthresultholder.baseresult> deletewithpermission(healthdataresolver.deleterequest request, activity activity) deletes health data required instant permission with the given request. calling this method, a file chooser is shown to acquire the user consent. after the user chooses all or some of files, those are finally deleted. it can be implemented asynchronously or synchronously. parameters: request - the request to delete health data activity - the activity that pop up the permission ui returns: the healthresultholder instance which resolves to the healthresultholder.baseresult for deleted health data throws: illegalargumentexception - if the request contains invalid instance type or null illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs on the connection since: 1.3.0 read public healthresultholder<healthdataresolver.readresult> read(healthdataresolver.readrequest request) reads health data with the given request. it can be implemented asynchronously or synchronously. parameters: request - the request to read health data returns: the healthresultholder instance which resolves to the healthdataresolver.readresult for health data to read throws: illegalargumentexception - if the request contains invalid instance type or null securityexception - if there is no permission to read for given health data illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs on the connection since: 1.0.0 readwithpermission public healthresultholder<healthdataresolver.readresult> readwithpermission(healthdataresolver.readrequest request, activity activity) reads health data required instant permission with the given request. calling this method, a file chooser is shown to acquire the user consent. after the user chooses all or some of files, those are finally read. it can be implemented asynchronously or synchronously. parameters: request - the request to read health data activity - the activity that pop up the permission ui returns: the healthresultholder instance which resolves to the healthdataresolver.readresult for health data to read throws: illegalargumentexception - if the request contains invalid instance type or null illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs on the connection since: 1.3.0 aggregate public healthresultholder<healthdataresolver.aggregateresult> aggregate(healthdataresolver.aggregaterequest request) aggregates health data with the given request. it can be implemented asynchronously or synchronously. parameters: request - the aggregate request for health data returns: the healthdataresolver.aggregateresult instance which resolves to the healthdataresolver.readresult for the requested aggregate throws: illegalargumentexception - if the request contains invalid instance type or null securityexception - if there is no permission to read for given health data illegalstateexception - if the instance of health data store is invalid or a remote-invocation error occurs on the connection since: 1.0.0