Class HealthDataStore

  • public class HealthDataStore
    extends Object
    This class provides connection to the health data store.

    App Manifest

    From Android 11, add the following element in your app's manifest. Otherwise, a connection with Samsung Health fails.

       <manifest . . . >
               <package android:name="" />

    Data Store Connection

    Health data in the health data store can be accessed after getting connection with the health data store.
    HealthDataStore requests to connect or disconnect with the health data store and its result can be checked with HealthDataStore.ConnectionListener.

    An example below shows how to request connection to the health data store and check the result.

       public class MainActivity extends Activity {
           // The state of connection
           private HealthDataStore mStore;
           private static final String APP_TAG = "MyApp";
           protected void onCreate(Bundle savedInstanceState) {
           public boolean onCreateOptionsMenu(Menu menu) {
               // Inflate the menu; this adds items to the action bar if it is present.
               getMenuInflater().inflate(, menu);
               return true;
           public boolean onOptionsItemSelected(MenuItem item) {
               // Handle action bar item clicks here. The action bar will
               // automatically handle clicks on the Home/Up button, so long
               // as you specify a parent activity in AndroidManifest.xml.
               int id = item.getItemId();
               if (id == {
                   return true;
               return super.onOptionsItemSelected(item);
           public HealthDataStore connect() {
               // Connect to the health data store
               mStore = new HealthDataStore(this, mCntListener);
               try {
               } catch (Exception e) {
                   Log.d(APP_TAG, "Connection fails.");
               return mStore;
           private final HealthDataStore.ConnectionListener mCntListener =
                   new HealthDataStore.ConnectionListener() {
               public void onConnected() {
                   Log.d(APP_TAG, "Health data service is connected.");
               public void onConnectionFailed(HealthConnectionErrorResult error) {
                   if (error.hasResolution()) {
                       // Resolve an error
                   } else {
                       Log.d(APP_TAG, "Health data service is not available.");
               public void onDisconnected() {
                   Log.d(APP_TAG, "Health data service is disconnected.");

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      static interface  HealthDataStore.ConnectionListener
      This interface provides the callback when the client is connected or disconnected with the health data store.