Skip to content

Commit

Permalink
Update aggregate data fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
RafhaanShah committed Mar 12, 2024
1 parent 16cb421 commit 755c33b
Show file tree
Hide file tree
Showing 19 changed files with 481 additions and 326 deletions.
89 changes: 23 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,90 +3,47 @@
[Tasker](https://tasker.joaoapps.com/) plugin to interface with [Health Connect](https://developer.android.com/health-connect) on Android

## Current Features
- ~~Get last X days step count~~ Retrieve all [Aggregate data](https://developer.android.com/health-and-fitness/guides/health-connect/develop/aggregate-data) for the last X days

## Installation
- Updates are currently released only on GitHub
- Get the latest APK from the [releases](https://github.com/RafhaanShah/TaskerHealthConnect/releases) page
- [Google Play Protect](https://developers.google.com/android/play-protect) may complain about untrusted applications because the APK is currently only signed with [Android Debug Certificates](https://developer.android.com/studio/publish/app-signing)

## Usage
- Run the app, it will check to make sure that Health Connect is installed and will prompt for required permissions
- Open Tasker, and look for 'Tasker Health Connect' inside Action -> Plugins

### Example Output

- Retrieve [Aggregate data](https://developer.android.com/health-and-fitness/guides/health-connect/develop/aggregate-data) for the last X days as JSON. See [HealthConnectRepository](app/src/main/java/com/rafapps/taskerhealthconnect/HealthConnectRepository.kt) and [HealthConnectDataTypes](app/src/main/java/com/rafapps/taskerhealthconnect/HealthConnectDataTypes.kt) for all data types, units, and JSON keys.
```json
[
{
"startTime":"2024-02-06T16:00:36.910Z",
"endTime":"2024-02-07T16:00:36.910Z",
"result":{
"Height_height_min":1.55,
"Height_height_avg":1.55,
"Height_height_max":1.55,
"Weight_weight_min":63,
"Weight_weight_avg":63.5,
"Weight_weight_max":64,
"BasalCaloriesBurned_energy_total":1523.29049265625,
"Nutrition_sugar_total":0,
"Nutrition_cholesterol_total":0,
"Nutrition_totalCarbohydrate_total":49.30000114440918,
"Nutrition_totalFat_total":1.0000000298023224,
"Nutrition_protein_total":1.600000023841858,
"Nutrition_dietaryFiber_total":5.5,
"Nutrition_iron_total":3.000000044703484E-4,
"Nutrition_vitaminA_total":2.0070000076293946E-4,
"Nutrition_vitaminC_total":0.0525,
"Nutrition_calcium_total":0.2390999984741211,
"Nutrition_calories_total":201,
"Nutrition_potassium_total":0.458,
"Nutrition_sodium_total":0.006,
"Nutrition_transFat_total":0,
"Nutrition_vitaminD_total":0,
"Nutrition_saturatedFat_total":0,
"TotalCaloriesBurned_energy_total":1523.29049265625,
"HeartRateSeries_bpm_min":68,
"HeartRate_bpm_min":68,
"HeartRateSeries_bpm_avg":79,
"HeartRate_bpm_avg":79,
"HeartRateSeries_bpm_max":92,
"HeartRate_bpm_max":92,
"Steps_count_total":5660,
"HeartRateSeries_count":48,
"HeartRate_count":48,
"SleepSession_duration":17040000
}
"FloorsClimbedRecord_FLOORS_CLIMBED_TOTAL": 5.75,
"ActiveCaloriesBurnedRecord_ACTIVE_CALORIES_TOTAL": 1532.1092
},
{
"startTime":"2024-02-05T16:00:36.910Z",
"endTime":"2024-02-06T16:00:36.910Z",
"result":{
"BasalCaloriesBurned_energy_total":1564.5,
"TotalCaloriesBurned_energy_total":1564.5,
"Steps_count_total":2
}
},
{
"startTime":"2024-02-07T16:00:36.910Z",
"endTime":"2024-02-08T12:01:36.910Z",
"result":{
"BasalCaloriesBurned_energy_total":1266.8881944444443,
"TotalCaloriesBurned_energy_total":1266.8881944444443,
"Steps_count_total":1423
}
"HeartRateRecord_BPM_AVG": 69,
"StepsRecord_COUNT_TOTAL": 19822
}
]
```

## Installation
- Updates are currently released only on GitHub
- Get the latest APK from the [releases](https://github.com/RafhaanShah/TaskerHealthConnect/releases) page
- [Google Play Protect](https://developers.google.com/android/play-protect) may complain about untrusted applications because the APK is currently only signed with [Android Debug Certificates](https://developer.android.com/studio/publish/app-signing)
- Check release / update notes as the plugin is not considered stable, and breaking API changes are to be expected

## Usage
- Run the app, it will check to make sure that Health Connect is installed and will prompt for required permissions
- Open Tasker, and look for 'Tasker Health Connect' inside Action -> Plugins

## Building
- Clone the repository: `git clone https://github.com/RafhaanShah/TaskerHealthConnect`
- Build with gradle: `./gradlew assembleDebug`
- Or just open in Android Studio and click run

## Testing
- Download the [Health Connect Toolbox](https://developer.android.com/health-and-fitness/guides/health-connect/test/health-connect-toolbox) to read and write test data
- Activities will have additional debug buttons to log output info on debug builds

# Contributing / Feature Requests
## Contributing / Feature Requests
- Contributions via pull requests are welcome!
- Tasker plugin documentation can be found [here](https://developer.android.com/guide/health-and-fitness/health-connect/get-started)
- Health Connect documentation can be found [here](https://tasker.joaoapps.com/pluginslibrary.html)
- Health Connect documentation can be found [here](https://developer.android.com/guide/health-and-fitness/health-connect/get-started)
- Tasker plugin documentation can be found [here](https://tasker.joaoapps.com/pluginslibrary.html)
- For feature requests please make a GitHub issue [here](https://github.com/RafhaanShah/TaskerHealthConnect/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) with details

## License
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ android {
}

buildFeatures {
buildConfig true
viewBinding true
}
}
Expand Down
107 changes: 59 additions & 48 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,49 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.rafapps.taskerhealthconnect">
xmlns:tools="http://schemas.android.com/tools">

<!-- For Tasker PLugins -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED"/>
<uses-permission android:name="android.permission.health.READ_BASAL_BODY_TEMPERATURE"/>
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE"/>
<uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE"/>
<uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE"/>
<uses-permission android:name="android.permission.health.READ_BODY_FAT"/>
<uses-permission android:name="android.permission.health.READ_BODY_TEMPERATURE"/>
<uses-permission android:name="android.permission.health.READ_BODY_WATER_MASS"/>
<uses-permission android:name="android.permission.health.READ_BONE_MASS"/>
<uses-permission android:name="android.permission.health.READ_CERVICAL_MUCUS"/>
<uses-permission android:name="android.permission.health.READ_EXERCISE"/>
<uses-permission android:name="android.permission.health.READ_DISTANCE"/>
<uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED"/>
<uses-permission android:name="android.permission.health.READ_EXERCISE"/>
<uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED"/>
<uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
<uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY"/>
<uses-permission android:name="android.permission.health.READ_HEIGHT"/>
<uses-permission android:name="android.permission.health.READ_HYDRATION"/>
<uses-permission android:name="android.permission.health.READ_INTERMENSTRUAL_BLEEDING"/>
<uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS"/>
<uses-permission android:name="android.permission.health.READ_MENSTRUATION"/>
<uses-permission android:name="android.permission.health.READ_NUTRITION"/>
<uses-permission android:name="android.permission.health.READ_OVULATION_TEST"/>
<uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION"/>
<uses-permission android:name="android.permission.health.READ_POWER"/>
<uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE"/>
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE"/>
<uses-permission android:name="android.permission.health.READ_SEXUAL_ACTIVITY"/>
<uses-permission android:name="android.permission.health.READ_SLEEP"/>
<uses-permission android:name="android.permission.health.READ_SPEED"/>
<uses-permission android:name="android.permission.health.READ_STEPS"/>
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED"/>
<uses-permission android:name="android.permission.health.READ_VO2_MAX"/>
<uses-permission android:name="android.permission.health.READ_WEIGHT"/>
<uses-permission android:name="android.permission.health.READ_WHEELCHAIR_PUSHES"/>

<!-- Health Connect Permissions https://developer.android.com/health-and-fitness/guides/health-connect/plan/data-types -->
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
<uses-permission android:name="android.permission.health.READ_BASAL_BODY_TEMPERATURE" />
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />
<uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE" />
<uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE" />
<uses-permission android:name="android.permission.health.READ_BODY_FAT" />
<uses-permission android:name="android.permission.health.READ_BODY_TEMPERATURE" />
<uses-permission android:name="android.permission.health.READ_BODY_WATER_MASS" />
<uses-permission android:name="android.permission.health.READ_BONE_MASS" />
<uses-permission android:name="android.permission.health.READ_CERVICAL_MUCUS" />

<uses-permission android:name="android.permission.health.READ_EXERCISE" />
<uses-permission android:name="android.permission.health.READ_DISTANCE" />
<uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED" />
<uses-permission android:name="android.permission.health.READ_EXERCISE" />
<uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY" />
<uses-permission android:name="android.permission.health.READ_HEIGHT" />
<uses-permission android:name="android.permission.health.READ_HYDRATION" />

<uses-permission android:name="android.permission.health.READ_INTERMENSTRUAL_BLEEDING" />
<uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS" />
<uses-permission android:name="android.permission.health.READ_MENSTRUATION" />
<uses-permission android:name="android.permission.health.READ_NUTRITION" />
<uses-permission android:name="android.permission.health.READ_OVULATION_TEST" />

<uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION" />
<uses-permission android:name="android.permission.health.READ_POWER" />
<uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE" />
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
<uses-permission android:name="android.permission.health.READ_SEXUAL_ACTIVITY" />
<uses-permission android:name="android.permission.health.READ_SLEEP" />
<uses-permission android:name="android.permission.health.READ_SPEED" />
<uses-permission android:name="android.permission.health.READ_STEPS" />

<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
<uses-permission android:name="android.permission.health.READ_VO2_MAX" />
<uses-permission android:name="android.permission.health.READ_WEIGHT" />
<uses-permission android:name="android.permission.health.READ_WHEELCHAIR_PUSHES" />

<!-- To see if Health Connect is installed -->
<queries>
<package android:name="com.google.android.apps.healthdata" />
<intent>
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent>
</queries>

<application
Expand All @@ -55,29 +64,31 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.TaskerHealthConnect"
tools:targetApi="31">
tools:targetApi="34">

<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name">
<meta-data
android:name="health_permissions"
android:resource="@array/health_permissions" />
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Android 13 -->
<intent-filter>
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
<!-- Android 14+ -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
<category android:name="android.intent.category.HEALTH_PERMISSIONS" />
</intent-filter>
</activity>

<activity
android:name=".tasker.GetHealthDataActivity"
android:name=".aggregated.AggregatedHealthDataActivity"
android:exported="true"
android:label="@string/get_data">
android:label="@string/aggregated_health_data">
<intent-filter>
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
</intent-filter>
Expand Down
Loading

0 comments on commit 755c33b

Please sign in to comment.