Smart Watch — Wear OS

GANESHKUMAR
5 min readDec 23, 2021

Usage of smart watch.

If we correlate the life before and after the pandemic, we can witness that people are more likely to focus on personal health, fitness, and hygiene now. ‘Wearables’ is one area that is helping the world in maintaining the streak. In recent days Fitness Bands, Smartwatches, VR, Smart Clothing, Ear Buds, and many other new wearable technologies came into existence. But let’s focus on Smartwatch for today.

This article today is solely from my personal experiences, in conjunction with principles from Android Wear OS and Samsung’s One UI.

What are the features of smart watch?

  • Heart Rate Monitors
  • Pedometers
  • Physical Activity Trackers(Running, Swimming, Cycling)
  • Blood Pressure
  • Sleep Monitors

Types Of Smart Watches

  • Smart Watch — Straightforward smartwatches are notification centers on your wrist. While many have a high-tech design, other designer smartwatches look just like traditional analogue watches from a distance. Up close, however, you’ll see that their display is really a screen which shows pop-up messages from your phone.
  • Hybrid smartwatch — A hybrid smartwatch is a classic analogue watch with a twist. While they don’t have a screen, they do connect to your phone via Bluetooth. You’ll receive alerts through the watch’s vibration and alarms. It’s even possible to programme them to point their hands to different numbers when you get messages from certain contacts, so you know to check your phone if it’s someone important. If your watch suddenly points to six o’clock, it might mean your boss is on the line; half past four and your spouse is calling. Hybrids combine analogue style with tech sophistication.
  • Fitness tracker — Fitness trackers have much of the functionality of smartwatches — they all tell the time, for one thing — but their main focus is on keeping you healthy by tracking your activity and pushing you to achieve your goals.

Perfect Watch for You

How to use a Smart Watch?

Using a smartwatch is simple, you can have yours up and running in moments. Here are the basic set-up steps that most models follow.

  • Charge your new smartwatch and turn it on.
  • Connect it to your phone via Bluetooth.
  • Download the apps and features you want to use, just as you would on a smartphone.
  • If it’s a hybrid, programme the watch to notify you about new messages.
  • Keep your smartwatch battery topped up by charging it overnight.

Quick Start for Smart Watch Wear OS

build.gradle App:

implementation 'com.google.android.gms:play-services-wearable:17.1.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.wear:wear:1.2.0'
compileOnly 'com.google.android.wearable:wearable:2.8.1'
implementation 'com.google.android.support:wearable:2.8.1'
implementation 'com.google.android.gms:play-services-fitness:21.0.0

Manifest:

<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-feature android:name="android.hardware.type.watch" />
<uses-feature
android:name="android.hardware.sensor.stepcounter"
android:required="true"
/>
<uses-feature
android:name="android.hardware.sensor.stepdetector"
android:required="true"
/>
<uses-feature
android:name="android.hardware.sensor.heartrate"
android:required="true"
/>
<uses-feature
android:name="android.hardware.sensor.heartrate.ecg"
android:required="true"
/>

<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.BODY_SENSORS" />

Connection Establishment

Connection between Watch and Mobile

Installation Guide

Download and Install Wear OS app from playstore. On the phone, in the Wear OS app, tap the Overflow button, and then tap Pair with Emulator. Tap the Settings icon. Under Device Settings, tap Emulator. Tap Accounts and select a Google Account, and follow the steps in the wizard to sync the account with the emulator.

https://developer.android.com/training/wearables/get-started/creating

Heart-bit Monitoring

A normal resting heart rate for adults ranges from 60 to 100 beats per minute. Generally, a lower heart rate at rest implies more efficient heart function and better cardiovascular fitness. For example, a well-trained athlete might have a normal resting heart rate closer to 40 beats per minute.

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.item_new_heart_bit)
sensorManager = getSystemService(SensorManager::class.java)
}
override fun
onSensorChanged(event: SensorEvent?) {
if (event?.values!!.isNotEmpty()) {
val value: Float = generateStepsCount()
Log.d("Heartrate", "Received new heart rate value: $value")
txt_heart_rate.text = event.values[0].toString()
}
}
override fun onAccuracyChanged(p0: Sensor?, p1: Int) {
}
override fun onPause() {
sensorManager?.unregisterListener(this)
super.onPause()
}

Steps Count

Many of us have used the step counter on our phones while we go for walk or run. It counts the total steps that the user has walked and displays it on the screen. The other name for the step counter is a pedometer. But have you ever thought about how can an app count our steps? What is the coding behind the working of this app? Let’s find the answer to these questions by making one.


override fun
onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.item_new_stepcount)

}
override fun onPause() {
super.onPause()
running = false
sensorManager
?.unregisterListener(this)
}

override fun onSensorChanged(event: SensorEvent?) {
if (running) {
txt_degree.text = event?.values?.get(0).toString()
val df = DecimalFormat("0.00")
}
}

override fun onAccuracyChanged(p0: Sensor?, p1: Int) {
}

override fun onResume() {
super.onResume()
running = true
var
stepsSensor = sensorManager?.getDefaultSensor(Sensor.TYPE_STEP_COUNTER)
if (stepsSensor == null) {
Toast.makeText(this, "No Step Counter Sensor !", Toast.LENGTH_SHORT).show()
} else {
sensorManager?.registerListener(this, stepsSensor, SensorManager.SENSOR_DELAY_UI)
}
}

Weather

This application will show the temperature of a location. To fetch weather information we will need an API. An API(Application Programming Interface) is a function that allows applications to interact and share data using various components and microservices. For this project, we will be using WeatherBit API for fetching weather data. WeatherBit API provides a fast and elegant way to fetch weather data.

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.item_new_weather)

fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)

obtainLocation()

}
private fun
obtainLocation() {
Log.e("lat", "function")
fusedLocationClient.lastLocation
.addOnSuccessListener { location: Location? ->
weather_url1
=
"https://api.weatherbit.io/v2.0/current?" + "lat=" + location?.latitude + "&lon=" + location?.longitude + "&key=" + api_id1
Log.e("lat", weather_url1.toString())
getTemp()
}
}

Stress Management

Smartwatches are flush with sensors to track your body. One of the most beneficial sensors allows you to measure stress. When using the stress level feature, smartwatches use heart rate data such as bpm to determine the interval between each heartbeat.

--

--