Use synthetic data providers to simulate sensor data from Health Services and test your app as though an exercise were really happening. You can use one of the preconfigured exercise profiles, or supply a custom one with flags.
See the Health Services samples repository on GitHub for example fitness apps.
Considerations when using the emulator
When using the Wear OS emulator, there are two options available for generating simulated data:
Synthetic data providers: Offers extensive options for data generation. This is the covered throughout the rest of this page.
To use synthetic data providers on the emulator, ensure developer options are enabled.
Emulator extended controls: The emulator in Android Studio offers the extended controls panel, available by clicking the three dots in the button bar. From the extended controls, the developer can load in KML/GPX files to simulate location, or specify the behaviour of the heart rate sensor.
To use extended controls to generate data for health services, ensure that sensor providers are enabled.
Enable synthetic data providers
- Enable developer options
- Issue the following adb command to enable synthetic providers:
$ adb shell am broadcast \
-a "whs.USE_SYNTHETIC_PROVIDERS" \
com.google.android.wearable.healthservices
Once synthetic providers are enabled, issue commands described later in this page to control the behavior of a “synthetic user.”
Reset to sensor providers
To switch back to using real sensors, run the following command:
$ adb shell am broadcast \
-a "whs.USE_SENSOR_PROVIDERS" \
com.google.android.wearable.healthservices
Supported metrics
Synthetic data providers currently support the following metrics:
- Heart rate
- Step count per minute
- GPS location (using a single default route)
- Duration of the activity
- Elevation and floors
- Sleep state (asleep/awake)
Pre-defined exercise activities
Change the synthesized activity by broadcasting one of the following actions.
- Walking:
whs.synthetic.user.START_WALKING
- Running:
whs.synthetic.user.START_RUNNING
- Hiking:
whs.synthetic.user.START_HIKING
- Swimming:
whs.synthetic.user.START_SWIMMING
- Running on treadmill:
whs.synthetic.user.START_RUNNING_TREADMILL
For example, this command starts simulating a walk:
$ adb shell am broadcast \
-a "whs.synthetic.user.START_WALKING" \
com.google.android.wearable.healthservices
Each of these activities has presets for the supported metrics:
Activity | Heart rate | Average speed | Elevation change | Use location |
---|---|---|---|---|
Walking | 120 bpm | 1.4 m/sec | 20.0 m/min | true |
Running | 170 bpm | 2.3 m/sec | 20.0 m/min | true |
Hiking | 150 bpm | 1.3 m/sec | 20.0 m/min | true |
Swimming | 150 bpm | 1.6 m/sec | 0.0 m/min | true |
Running treadmill | 160 bpm | 2.3 m/sec | 20.0 m/min | false |
Stop an exercise activity
To stop the ongoing activity, use the following command:
$ adb shell am broadcast \
-a "whs.synthetic.user.STOP_EXERCISE" \
com.google.android.wearable.healthservices
Custom exercise activity
For more precise control over what metrics are generated, start a custom
exercise activity by using the action string whs.synthetic.user.START_EXERCISE
and providing any combination of the following flags:
--ei exercise_options_duration_secs <int>
Duration of the exercise in seconds. Default:0
.--ei exercise_options_heart_rate <int>
Heart rate in beats per minute. Average:70
.--ef exercise_options_average_speed <float>
Average speed in meters per second. Also affects cadence (steps per minute). Default:0
.--ez exercise_options_use_location <boolean>
Whether to emit location data during the exercise (using a default route). Default:false
.--ef exercise_options_max_elevation_rate <float>
Maximum possible elevation change rate in meters per minute. Default:0
.
For example, set exercise options in the following way:
$ adb shell am broadcast \
-a "whs.synthetic.user.START_EXERCISE" \
--ei exercise_options_heart_rate 90 \
--ef exercise_options_average_speed 1.2 \
--ez exercise_options_use_location true \
com.google.android.wearable.healthservices
To end the activity, see Stop an exercise activity.
Control sleep state
It is possible to trigger a particular sleep state for the synthetic user. At the moment, there are only two supported states: asleep and awake. To switch between the two, use the commands below.
To enter ‘asleep’ state, do the following:
$ adb shell am broadcast \
-a "whs.synthetic.user.START_SLEEPING" \
com.google.android.wearable.healthservices
To enter ‘awake’ state do the following:
$ adb shell am broadcast \
-a "whs.synthetic.user.STOP_SLEEPING" \
com.google.android.wearable.healthservices