An Android smartwatch application to read and send sensor data to the server.
- This application is based on Google’s ExerciseSampleCompose using ExerciseClient API.
- A Room database has been added to save exercise metrics such as heart rate, calories, speed, etc., in the local database on the watch.
- It also uses Ktor OkHttp to send exercise data to the server using web sockets.
- See overview here
- AndroidStudio
- See Create and run an app on Wear OS for more information on how to create a Wear OS project.
- Tested on Samsung Galaxy Watch 4
- In order to get search location suggestions, we use either Google Maps Places API
Nominatim OSM API.
- To use Google Maps Places API, you need to have a Google Cloud Platform (GCP) account and enable the Places API.
- To use Nominatim OSM API, you do not need an API key.
- In
app/src/main/java/com/hci/tom/android/presentation/ExerciseViewModel.kt
, you can modify the options to choose which API you would like to use for search locations.
companion object {
// 0 for OpenStreetMap, 1 for Google Maps
private const val PLACES_OPTION = 0
}
- Create an object class named
ApiKeys.kt
inapp/src/main/java/com/hci/tom/android/network
directory and add the following code:
package com.hci.tom.android.network
object ApiKeys {
const val GOOGLE_MAP_API_KEY = "{YOUR_GOOGLE_MAPS_API_KEY}"
}
- In
app/src/main/java/com/hci/tom/android/network/Credentials.kt
, modify the code accordingly:
package com.hci.tom.android.network
object Credentials {
const val SERVER_URL = "ws://{IP_ADDRESS}:{SERVER_PORT}"
}
You can set the IP address to
10.0.2.2
if you are using the emulator. This is because the emulator runs behind a virtual router isolated from your computer network interfaces,10.0.2.2
is an alias to your host loopback interface. (127.0.0.1 on development machine) You can refer to https://developer.android.com/studio/run/emulator-networking for more info.
- Debugging
- Go to platform-tools
cd <USER_FOLDER>\Android\Sdk\platform-tools
(<USER_FOLDER>
is the folder where Android SDK is installed, e.e.,C:\Users\<NAME>\AppData\Local\
) - Connect adb,
adb connect <WATCH_IP>
- To disconnect,
adb disconnect
- To simulate an exercise session on an emulator, you can use the following command in the terminal:
adb shell am broadcast -a "whs.synthetic.user.START_EXERCISE"--ei exercise_options_heart_rate 90 --ef exercise_options_average_speed 2.5 --ez exercise_options_use_location true com.google.android.wearable.healthservices
- You can visit this link if you would like to modify the simulated run stats. Ensure that developer options is enabled on the emulator as well.
- To enable microphone input on an emulator, you can use the following command in the terminal:
adb emu avd hostmicon
Make sure to enable this option in extended controls as well, you have to enable it everytime you restart the emulator:
- Change to Project View at the top left of Android Studio.
- Create your proto file in
app/src/main/proto
, create a newproto
directory if necessary. Please refer here for more info on how to structure your proto file.
- You can set the package directory using
option java_package = "{dir_path}"
and the generated class name usingoption java_outer_classname = "{class_name}"
before the message and after the syntax. - Build the project and the generated class should be
in
app/build/generated/source/proto/debug/java/{dir_path}
and you can import the class from there to use the class builder functions.
Intellij IDEA
- Install the ktlint plugin in the Marketplace here
Command-Line
- Install ktlint Guide
- Run
ktlint --editorconfig=.editorconfig