com.samsung.android.service.health.tracking

Class HealthTrackingService

  • java.lang.Object
    • com.samsung.android.service.health.tracking.HealthTrackingService


  • public class HealthTrackingService
    extends Object
    HealthTrackingService initiates a connection to Samsung's Health Tracking Service and provides an HealthTracker instance to track a HealthTrackerType.

      
       public class MainActivity extends Activity {
      
           private HealthTrackingService healthTrackingService = null;
           private HealthTracker ecgTracker = null;
      
       private final ConnectionListener connectionListener = new ConnectionListener() {
           @Override
           public void onConnectionSuccess() {
                   // Connection with Health Platform succeeded. Check capability.
                   List<HealthTrackerType> availableTrackers = healthTrackingService.getTrackingCapability().getSupportHealthTrackerTypes();
                   if (!availableTrackers.contains(HealthTrackerType.ECG_ON_DEMAND)) {
                       // Tracking Electrocardiogram (ECG) On-Demand is not available.
                       // Display a proper message to the user. 
                   } else {
                       ecgTracker = healthTrackingService.getHealthTracker(HealthTrackerType.ECG_ON_DEMAND);
                   }
           }
      
           @Override
           public void onConnectionEnded() {
                   // The connection with Health Platform was ended.
           }
      
           @Override
           public void onConnectionFailed(HealthTrackerException exception) {
                   //Check the error code and resolve it.
                   if (exception.hasResolution()) {
                       // Display a proper message before calling resolve().
                       exception.resolve(MainActivity.this); // Jumping to an application market to install or update Health Platform.
                   } else {
                       // Display a proper message for the exception.
                   }
           }
       }
      
           @Override
           protected void onCreate(Bundle savedInstanceState) {
               // Check and request permission.
               if (ActivityCompat.checkSelfPermission(getApplicationContext(), "android.permission.BODY_SENSORS")
                       == PackageManager.PERMISSION_DENIED) {
                   requestPermissions(this, new String[]{Manifest.permission.BODY_SENSORS}, 0);
               }
      
               try {
       // Connect the Health Tracking Service.
                   healthTrackingService = new HealthTrackingService(connectionListener, context);
       healthTrackingService.connectService();
               } catch (Throwable t) {
                   // Exception handling.
               }
           }
       }
       

    Since:
    1.0.0