Service | SampleService


SampleService sample download

Health Service provides a sample application 'SampleService' to show how to post your tracker tile and work with Samsung Health.

Prerequisites

Prerequisites to run SampleService are:

  • Prepare an Android device that supports 6.0 Marshmallow (API level 23) or above. (Samsung and non-Samsung devices are available both.)

  • Install Samsung Health.

  • Turn on the developer mode.

  • Import SampleService with Android Studio (or Eclipse).

  • Run SampleService on the device.

Overview

If Samsung Health and SampleService are installed properly, you can:

find the Sample tracker on the Samsung Health‘s tracker list after installing the sample app.

Launch some Samsung Health's available tracker.

If you subscribe to the Sample tracker and go back to the Samsung Health‘s main screen, its tile will be shown as the middle figure. Its tile is posted with TRACKER_TILE_TYPE_1 at the first time. The sample app's posted tile will be changed to the different tile template - TRACKER_TILE_TYPE_3 that includes a content value, unit, and updated time whenever the tile's button is tapped.

The posted tracker tile's ID can be checked on SampleService as the figure's third screenshot and you can remove the posted tracker tile.

Connection to Health Data Store

The app needs to use the SDK's Health Data basically and connect to the health data store to handle various exceptions whether the app can work with Samsung Health on the device.

But SampleService doesn't include the Health Data API usage because it focuses to show the tracker usage only.

See the SimpleHealth sample application in the SDK or the Health Data‘s Programming Guide for the health data store connection.

Source Description

Source / Resource Description
AndroidManifest.xml

Registering the tracker tile button's service intent MyTrackerService with the <service> element.
Declaring Samsung Health's PluginService with the <service> element.

res/values/

 
sample_tracker.xml

Defining tracker with its metadata.
src/com/samsung/android/app/sampleservice/

 
MainActivity.java

SampleService's main activity.
[TrackerManager]
   * Showing a list for some Samsung Health trackers.
   * Launching the selected tracker.
[TrackerTileManager]
   * Showing the posted tile’s ID on the Samsung Health’s main screen.
   * Containing a button to remove a posted tile.

MyTracker.java

Checking the feature availability.
Implementing the app’s tracker.
   - Implementing TrackerEventListener to receive the following tracker events from Samsung Health:
     * If the user subscribes or unsubscribes the SampleService’s tracker,
       => onSubscribed(), onUnsubscribed()
     * If Samsung Health goes to the background,
       => onPaused()
     * If Samsung Health requests the tracker tile of SampleService,
       => onTileRequested()
     * If the posted tile is removed from the Samsung Health’s main screen,
       => onTileRemoved()
   - Posting or updating the tracker tile of SampleServicedepending on the received tracker event.