public final class HealthConnectionErrorResult extends Object
PLATFORM_NOT_INSTALLED
OLD_VERSION_PLATFORM
PLATFORM_DISABLED
USER_AGREEMENT_NEEDED
USER_PASSWORD_NEEDED
Samsung Health SDK for Android helps you to handle all available error cases with HealthConnectionError when your application connects to the health data store.
HealthConnectionError
HealthConnectionError is retrieved in HealthDataStore.ConnectionListener's event handler and all Samsung Health's partner applications need to check the health data store's connection error mandatorily.
HealthDataStore.ConnectionListener
The following example shows how to handle the connection error.
public class MainActivity extends Activity { private HealthDataStore mStore; private HealthConnectionErrorResult mConnError; private static MainActivity mInstance = null; @Override public void onCreate(Bundle savedInstanceState) { // ... mStore = new HealthDataStore(this, mConnectionListener); mStore.connectService(); } @Override public void onDestroy() { mStore.disconnectService(); // ... } private final HealthDataStore.ConnectionListener mConnectionListener = new HealthDataStore.ConnectionListener() { @Override public void onConnected() { // Connected } @Override public void onConnectionFailed(HealthConnectionErrorResult error) { // Connection fails showConnectionFailureDialog(error); } @Override public void onDisconnected() { // Connection is disconnected } }; private void showConnectionFailureDialog(HealthConnectionErrorResult error) { AlertDialog.Builder alert = new AlertDialog.Builder(this); mConnError = error; if (mConnError.hasResolution()) { switch(error.getErrorCode()) { case HealthConnectionErrorResult.PLATFORM_NOT_INSTALLED: message = "Please install Samsung Health"; break; case HealthConnectionErrorResult.OLD_VERSION_PLATFORM: message = "Please upgrade Samsung Health"; break; case HealthConnectionErrorResult.PLATFORM_DISABLED: message = "Please enable Samsung Health"; break; case HealthConnectionErrorResult.USER_AGREEMENT_NEEDED: message = "Please agree to Samsung Health policy"; break; default: message = "Please make Samsung Health available"; break; } } else { // In case that the device doesn't support Samsung Health, // hasResolution() returns false also. alert.setMessage(R.string.msg_conn_not_available); } alert.setPositiveButton(R.string.ok, (dialog, id) -> { if (error.hasResolution()) { error.resolve(MainActivity.this); } }); if (error.hasResolution()) { alert.setNegativeButton("Cancel", null); } alert.show(); } }
static int
CONNECTION_FAILURE
OLD_VERSION_SDK
PLATFORM_SIGNATURE_FAILURE
TIMEOUT
UNKNOWN
int
getErrorCode()
boolean
hasResolution()
void
resolve(Activity activity)
public static final int UNKNOWN
0
public static final int CONNECTION_FAILURE
1
public static final int PLATFORM_NOT_INSTALLED
To resolve it:
"<queries>"
resolve(android.app.Activity)
2
public static final int OLD_VERSION_SDK
3
public static final int OLD_VERSION_PLATFORM
To resolve it, call resolve(android.app.Activity). It leads the user to install the latest Samsung Health on an app seller site.
4
public static final int TIMEOUT
5
public static final int PLATFORM_DISABLED
To resolve it, call resolve(android.app.Activity). It leads the user to activate Samsung Health through the phone's Settings.
6
public static final int USER_PASSWORD_NEEDED
Some devices can request a password to protect the user's data. The password for the health data access can be registered in Samsung Health by the user. Then the user can enter the password through the password pop-up window. If the predetermined time passed without the valid password input, TIMEOUT occurs.
Its constant value is 7.
7
public static final int PLATFORM_SIGNATURE_FAILURE
8
public static final int USER_AGREEMENT_NEEDED
To resolve it, call reslove. It leads the user to the Samsung Health's service agreement page.
reslove
9
public int getErrorCode()
HealthDataStore.ConnectionListener.onConnectionFailed(HealthConnectionErrorResult)
public boolean hasResolution()
The SDK supports Marshmallow and above Android devices including non-Samsung devices. And it works with Samsung Health. There is no connection issue on most devices but it is not available occasionally depending on the device's specification.
This API lets you know whether the device supports Samsung Health. The returned false involves that the device is not available for Samsung Health.
false
android.permission.INTERNET
true
resolve(Activity)
public void resolve(Activity activity)
It handles the following errors and operations. Show a proper message for each error case in your application before call this method.
activity
IllegalArgumentException
null