Reputation: 11
I'm trying to record heart rate data from an emulated watch (running Wear OS 4/ API Level 14) and the most recent version of Android Studio Preview. I am using Android Studio's PassiveMonitoringClient (Part of Android Studio Health Services). Here's a snippet of the code that I just wrote in MainActivity OnCreate. Right now, I just want a minimum working example of reading in some heart rate data.
val healthClient = HealthServices.getClient(this)
val passiveMonitoringClient = healthClient.passiveMonitoringClient
val passiveListenerConfig = PassiveListenerConfig.builder()
.setDataTypes(setOf(DataType.HEART_RATE_BPM, DataType.GOLF_SHOT_COUNT))
.build()
val passiveListenerCallback: PassiveListenerCallback = object : PassiveListenerCallback {
override fun onNewDataPointsReceived(dataPoints: DataPointContainer) {
for (dataPoint in dataPoints.sampleDataPoints) {
val heartRate = dataPoint.value
Log.i("WearApp", "Received heart rate: $heartRate")
}
}
}
passiveMonitoringClient.setPassiveListenerCallback(
passiveListenerConfig,
passiveListenerCallback,
)
I am using adb commands to start the activity (walking):
adb shell am broadcast \
-a "whs.USE_SYNTHETIC_PROVIDERS" \
com.google.android.wearable.healthservices
and, subsequently,
adb shell am broadcast \
-a "whs.synthetic.user.START_WALKING" \
com.google.android.wearable.healthservices
The docs say that the start walking activity should start generating heart rate data, but my log line is never being printed, and I verified that the callback is never being called.
Note that I can verify that the adb is connected to the correct emulated device, but I'm unsure if the commands are working as intended.
I should have the relevant permissions in my manifest. Here it is just in case:
<uses-permission android:name="android.permission.BODY_SENSORS" />
<uses-permission android:name="android.permission.BODY_SENSORS_BACKGROUND"/>
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
I do not have any permission request setup in the app, it's just a base project with this code to test the sensor reading for now before I incorporate it into my main app.
Thanks!
Upvotes: 1
Views: 133
Reputation: 381
Starting with Wear OS 4, the adb commands no longer work -- the emulator generates data automatically. Try running PassiveGoalsCompose in the Wear 4 emulator to see this in action.
Upvotes: 0