public class HealthDataStore extends Object
<manifest . . . > <queries> <package android:name="com.sec.android.app.shealth" /> </queries> </manifest>
HealthDataStore
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"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); connect(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override 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 == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } public HealthDataStore connect() { // Connect to the health data store mStore = new HealthDataStore(this, mCntListener); try { mStore.connectService(); } catch (Exception e) { Log.d(APP_TAG, "Connection fails."); e.printStackTrace(); } return mStore; } private final HealthDataStore.ConnectionListener mCntListener = new HealthDataStore.ConnectionListener() { @Override public void onConnected() { Log.d(APP_TAG, "Health data service is connected."); } @Override public void onConnectionFailed(HealthConnectionErrorResult error) { if (error.hasResolution()) { // Resolve an error } else { Log.d(APP_TAG, "Health data service is not available."); } } @Override public void onDisconnected() { Log.d(APP_TAG, "Health data service is disconnected."); } }; }
static interface
HealthDataStore(Context context, HealthDataStore.ConnectionListener listener)
void
connectService()
connectService(long timeout)
disconnectService()
public HealthDataStore(Context context, HealthDataStore.ConnectionListener listener)
context
listener
IllegalArgumentException
null
public void connectService()
connectService(long)
The connection result can be checked in the following handlers.
HealthDataStore.ConnectionListener.onConnected()
HealthDataStore.ConnectionListener.onConnectionFailed(HealthConnectionErrorResult)
IllegalStateException
public void connectService(long timeout)
timeout
public void disconnectService()
HealthDataStore.ConnectionListener.onDisconnected()