com.samsung.android.sdk.healthdata

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.

    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 in HealthDataStore.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 is 0.
        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 is 1.
        Since:
        1.0.0
        See Also:
        Constant Field Values
      • 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.

        Its constant value is 3.
        Since:
        1.0.0
        See Also:
        Constant Field Values
      • TIMEOUT

        public static final int TIMEOUT
        The connection time exceeded the limit. Its constant value is 5.
        Since:
        1.0.0
        See Also:
        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 is 8.
        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 reslove. It leads the user to the Samsung Health's service agreement page.

        Its constant value is 9.
        Since:
        1.0.0
        See Also:
        resolve(android.app.Activity), Constant Field Values
    • Method Detail

      • 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 returned false 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. Call resolve(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.

        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 is null or invalid
        Since:
        1.0.0