Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passive Goals - Not getting Steps, Calories etc. Getting only Heart_rate #75

Open
harishvgk opened this issue Jan 23, 2023 · 15 comments
Open

Comments

@harishvgk
Copy link

Passive Goals - Not getting Steps, Calories etc. Getting only Heart_rate

Environment: Mac OSx - Android Studio IDE, Wear OS Emulator

Set daily calories - here private val dataTypes = setOf(DataType.HEART_RATE_BPM, DataType.DAILY_CALORIES)

class HealthServicesRepository(context: Context) {

private val healthServicesClient = HealthServices.getClient(context)

private val passiveMonitoringClient = healthServicesClient.passiveMonitoringClient

private val dataTypes = setOf(DataType.HEART_RATE_BPM, DataType.DAILY_CALORIES)

private val passiveListenerConfig = PassiveListenerConfig(

    dataTypes = dataTypes,

    shouldUserActivityInfoBeRequested = false,

    dailyGoals = setOf(),

    healthEventTypes = setOf()

)

......
......

But after that not get any data points on the onNewDataPointsReceived method.

class PassiveDataService : PassiveListenerService() {

private val repository = PassiveDataRepository(this)

override fun onNewDataPointsReceived(dataPoints: DataPointContainer) {

    runBlocking {

        dataPoints.getData(DataType.HEART_RATE_BPM).latestHeartRate()?.let {

            repository.storeLatestHeartRate(it)

        }

    }

}

}

Please help me to get heart rate, daily steps, daily calories, distance etc from PassiveData sample app with correct permissions, settings and flows required

Thanks in Advance

@garanj
Copy link
Contributor

garanj commented Jan 23, 2023

Hello

Are you using the synthetic tracker on your emulator to generate the data?

see: Try it with synthetic data

@harishvgk
Copy link
Author

harishvgk commented Jan 24, 2023

@garanj
Yes, I tried with the Synthetic tracker. But not getting data in the callback method. Please check this, and correct me if anything done is wrong

(1) to get data we need to request the type

  • private val dataTypes = setOf(DataType.HEART_RATE_BPM, DataType.DAILY_CALORIES). Here only one element and specifically HEART_RATE_BPM is taken. In that case, heart rate data is obtained. If any other single parameter DAILY_CALORIES or multiple params as a Set is given, none of the data is obtained

(2) Synthetic data works only sometimes, not always. And if so, it can be seen in logcat only, not getting any data points inside the app

Thanks in Advance

@garanj
Copy link
Contributor

garanj commented Jan 24, 2023

Thanks, can you confirm which permissions you are requesting in your AndroidManifest.xml?

@harishvgk
Copy link
Author

Thanks @garanj for your quick response

Permissions:

<uses-permission android:name="android.permission.BODY_SENSORS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<!-- For ambient mode. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- For showing an ongoing notification. -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

.....

Also please confirm if the below code is the right way to get multiple sensor datapoints:

private val dataTypes = setOf(DataType.HEART_RATE_BPM, DataType.DAILY_CALORIES, ...... etc)
// in the sample only 1 sensor data type was set private val dataTypes = setOf(DataType.HEART_RATE_BPM)

private val passiveListenerConfig = PassiveListenerConfig(

dataTypes = dataTypes, // dataTypes is set here. 

shouldUserActivityInfoBeRequested = false,

dailyGoals = setOf(),

healthEventTypes = setOf()

)

@harishvgk
Copy link
Author

@garanj and Team
This is my requirement:

Wear OS app collects heart rate, calories, distance, and steps in Passive Data mode.
App connects to AWS IoT in the background to send a batch of data points to AWS

I am looking for a Passive Data Sample code that collects all the data points: heart rate, calories, distance, and steps.
The existing passive data sample works for only one
private val dataTypes = setOf(DataType.HEART_RATE_BPM)

Please help

Thanks,
Harish

@garanj
Copy link
Contributor

garanj commented Jan 24, 2023

Thanks Harish, taking a look. Please bear with me I will aim to dive into this in the next day.

@harishvgk
Copy link
Author

Sure @garanj . Thank you

@garanj
Copy link
Contributor

garanj commented Jan 25, 2023

@harishvgk I believe I can replicate your issue and am discussing it further internally.

In order to unblock your development, do you have a physical device you are able to use instead of the emulator? And can you confirm whether you're seeing the issue on that device?

@garanj garanj closed this as completed Jan 25, 2023
@garanj garanj reopened this Jan 25, 2023
@harishvgk
Copy link
Author

@garanj I don't have a physical device. I can create a build, send it and get it tested in my Friend's watch.
But the emulator itself says "No permission granted" even after the required permissions are given in the AndroidManifest and accepted when the app run

Other issue is, how to get more sensor data from this sample app? Here we are stuck up

private val dataTypes = setOf(DataType.HEART_RATE_BPM) .... // Any option to add CALORIE, STEPS etc.
Any other changes required? Basically we need to get multiple data points of different types as a batch

Thanks,
Harish

@garanj
Copy link
Contributor

garanj commented Jan 25, 2023

As well as specifying the permissions in the Manifest, are you also requesting them at runtime?
You need to ensure they've each been requested and granted at runtime.

(To help step past that issue for now and focus on the data issue, you can grant the app permission via adb shell pm grant <package> <permission> in the interim)

You're correct, you need to add the dataTypes to that set. However, I too am experiencing an issue getting data back from PassiveMonitoringClient for data types other than Heart Rate, when using the emulator specifically, so we're looking at that in more depth now.

@garanj
Copy link
Contributor

garanj commented Jan 26, 2023

Hi @harishvgk, looking at this issue, it appears that support in the synthetic tracker for producing Calories was not introduced until after the version of Health Services that is on the emulator: The version of Health Services on the emulator is unfortunately a bit old.

This is not the first issue that has arisen because of the Health Services version on the emulator being somewhat old, and we are actively investigating how we can ensure it is updated and remains updated.

In the interim, the immediate option, I'm afraid, is to do the testing on a physical device. We're exploring options and hopefully we'll have a better answer in due course.

@harishvgk
Copy link
Author

@garanj Thanks for the details shared. It's really helpful and informative.

The ExerciseSample app running the Wear OS emulator is getting Calories along with the Heart rate per minute.

I will try to use the app on a physical device and update you

Thanks
Harish

@garanj
Copy link
Contributor

garanj commented Jan 27, 2023

Hi @harishvgk

An alternative that may work for you is to update the Health Services version via Play yourself on the emulator.

The caveat I will add here is that if you are using a Mac with an M1 chip, then Play is not currently available on the Wear emulator, so this won't work. But if you are using a different device, then this is worth a try.

You'll need to sign into Play on the watch and then use Play to upgrade the version of Health Services.

Let me know if this unblocks you.

Garan

@Agusioma
Copy link

Agusioma commented Jun 6, 2023

@garanj, I am getting the same issue here using my Samsung device. The Health Services app is updated on the device. But it only recognises the heart rate when I log this:- Log.i("THE SET!", dataPoints.dataTypes.toString()). That is, this is displayed:
THE SET! I [DataType(name=HeartRate, timeType=SAMPLE, class=Double, isAggregate=false)]. When using the emulator, however, it logs the heart rate and daily steps, [DataType(name=HeartRate, timeType=SAMPLE, class=Double, isAggregate=false), DataType(name=Daily Steps, timeType=INTERVAL, class=Long, isAggregate=false)]. In which when I try using the Synthetic data to record the steps it always displays 0. I am using the PassiveMonitoring Client. And I am logging this in the onNewDataPointsReceived.

@hms-douglas
Copy link

I'm having pretty much the same problem... I'm running on mine watch 5
In my case when samsung health app is on foreground I get all (steps, calories, and so on), but when the app (samsung health) is on background/closed I only get the heart rate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants