Class HealthConnectionErrorResult
- java.lang.Object
-
- com.samsung.android.sdk.healthdata.HealthConnectionErrorResult
-
public final class HealthConnectionErrorResult extends Object
This class handles errors raised by connection failure to the health data store.Considerations for Connection Failure
A partner app works with Samsung Health. The partner app can meet the following error cases when it connects to Samsung Health.Connection error Description PLATFORM_NOT_INSTALLED
Samsung Health is not installed. OLD_VERSION_PLATFORM
Installed Samsung Health's version is old. PLATFORM_DISABLED
Samsung Health is disabled. USER_AGREEMENT_NEEDED
The user didn't agree to Samsung Health's Terms & Conditions and Privacy Policies. USER_PASSWORD_NEEDED
Samsung Health is locked by the user password. Handling Connection Exceptions
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
is retrieved inHealthDataStore.ConnectionListener
's event handler and all Samsung Health's partner applications need to check the health data store's connection error mandatorily.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(); } }
- Since:
- 1.0.0
- See Also:
HealthDataStore.ConnectionListener
-
-
Field Summary
Fields Modifier and Type Field and Description static int
CONNECTION_FAILURE
The connection is not established in the health data framework.static int
OLD_VERSION_PLATFORM
The version of the health data framework is outdated to cooperate with SDK.static int
OLD_VERSION_SDK
The SDK's Data library version is outdated to cooperate with the Samsung Health's health data framework.static int
PLATFORM_DISABLED
The health data framework is disabled.static int
PLATFORM_NOT_INSTALLED
Samsung Health is not installed.static int
PLATFORM_SIGNATURE_FAILURE
It fails to check the signature of the health data framework.static int
TIMEOUT
The connection time exceeded the limit.static int
UNKNOWN
Unknown error.static int
USER_AGREEMENT_NEEDED
The user did not agree to terms and conditions, and privacy policy of Samsung Health yet.static int
USER_PASSWORD_NEEDED
The user cancels the password input explicitly on the password pop-up window.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description int
getErrorCode()
Gets the error code of connection failure.boolean
hasResolution()
Checks whether the given error has a resolution.void
resolve(Activity activity)
Resolves an error with an activity which is able to get the user's feedback for possible error cases.
-
-
-
Field Detail
-
UNKNOWN
public static final int UNKNOWN
Unknown error. Its constant value is0
.- Since:
- 1.0.0
- See Also:
- Constant Field Values
-
CONNECTION_FAILURE
public static final int CONNECTION_FAILURE
The connection is not established in the health data framework. Its constant value is1
.- Since:
- 1.0.0
- See Also:
- Constant Field Values
-
PLATFORM_NOT_INSTALLED
public static final int PLATFORM_NOT_INSTALLED
Samsung Health is not installed.To resolve it:
- If your app runs on Android 11, check your app manifest whether the
"<queries>"
element is added. See the App Manifest guide. - Call
resolve(android.app.Activity)
. It leads the user to install Samsung Health on an app seller site.
2
.- Since:
- 1.0.0
- See Also:
resolve(android.app.Activity)
, Constant Field Values
- If your app runs on Android 11, check your app manifest whether the
-
OLD_VERSION_SDK
public static final int OLD_VERSION_SDK
The SDK's Data library version is outdated to cooperate with the Samsung Health's health data framework.To resolve it:
- Apply the latest Data library to your app.
- If your app uses the latest Data library, create an activity to update to install your latest app.
3
.- Since:
- 1.0.0
- See Also:
- Constant Field Values
-
OLD_VERSION_PLATFORM
public static final int OLD_VERSION_PLATFORM
The version of the health data framework is outdated to cooperate with SDK.To resolve it, call
Its constant value isresolve(android.app.Activity)
. It leads the user to install the latest Samsung Health on an app seller site.4
.- Since:
- 1.0.0
- See Also:
resolve(android.app.Activity)
, Constant Field Values
-
TIMEOUT
public static final int TIMEOUT
The connection time exceeded the limit. Its constant value is5
.- Since:
- 1.0.0
- See Also:
- Constant Field Values
-
PLATFORM_DISABLED
public static final int PLATFORM_DISABLED
The health data framework is disabled.To resolve it, call
Its constant value isresolve(android.app.Activity)
. It leads the user to activate Samsung Health through the phone's Settings.6
.- Since:
- 1.0.0
- See Also:
resolve(android.app.Activity)
, Constant Field Values
-
USER_PASSWORD_NEEDED
public static final int USER_PASSWORD_NEEDED
The user cancels the password input explicitly on the password pop-up window.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
.- Since:
- 1.0.0
- See Also:
- Constant Field Values
-
PLATFORM_SIGNATURE_FAILURE
public static final int PLATFORM_SIGNATURE_FAILURE
It fails to check the signature of the health data framework. Its constant value is8
.- Since:
- 1.0.0
- See Also:
- Constant Field Values
-
USER_AGREEMENT_NEEDED
public static final int USER_AGREEMENT_NEEDED
The user did not agree to terms and conditions, and privacy policy of Samsung Health yet. The health data framework is not activated before agreement.To resolve it, call
Its constant value isreslove
. It leads the user to the Samsung Health's service agreement page.9
.- Since:
- 1.0.0
- See Also:
resolve(android.app.Activity)
, Constant Field Values
-
-
Method Detail
-
getErrorCode
public int getErrorCode()
Gets the error code of connection failure. Usually it is called inHealthDataStore.ConnectionListener.onConnectionFailed(HealthConnectionErrorResult)
. It's required to resolve the error depending on its returned error code.- Returns:
- The error code
- Since:
- 1.0.0
-
hasResolution
public boolean hasResolution()
Checks whether the given error has a resolution.
Whether the Device Supports Samsung Health
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 returnedfalse
involves that the device is not available for Samsung Health.- Precondition:
- Check the network connection.
- Permission:
-
android.permission.INTERNET
- Returns:
true
if the platform provides a resolution for the error. Callresolve(Activity)
.
false
in the following cases:
- if the device doesn't support Samsung Health
- if there is no resolution for the error
- Since:
- 1.0.0
-
resolve
public void resolve(Activity activity)
Resolves an error with an activity which is able to get the user's feedback for possible error cases.It handles the following errors and operations. Show a proper message for each error case in your application before call this method.
Error Operation PLATFORM_NOT_INSTALLED Linked to the application installation page OLD_VERSION_PLATFORM Linked to the application installation page PLATFORM_DISABLED Linked to Settings of the device to turn on Samsung Health USER_AGREEMENT_NEEDED Linked to the starting screen of Samsung Health to get the user's agreement - Precondition:
- Check the network connection.
- Permission:
-
android.permission.INTERNET
- Parameters:
activity
- An activity which resolves the error with the user's feedback. Usually it's the main activity of your application.- Throws:
IllegalArgumentException
- If the specified input isnull
or invalid- Since:
- 1.0.0
-
-