Reputation: 1286
I have an Android app and I want to read the heart rate from any connected Android watch (Wear OS, Tizen, etc). Is this possible without developing a wearable app?
I tried registering a listener on the Sensor.TYPE_HEART_RATE
but I don't see any of the 3 watches that I have show up (Ticwatch E, Ticband, Gear S2). I ensured I request the Manifest.permission.BODY_SENSORS
permission.
sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager?
heartRateSensor = sensorManager?.getDefaultSensor(Sensor.TYPE_HEART_RATE)
val registered = sensorManager?.registerListener(this, heartRateSensor, SensorManager.SENSOR_DELAY_NORMAL)
Log.i(TAG, if (registered!!) "Registered Listener" else "Failed to register listener")
Upvotes: 8
Views: 4025
Reputation: 1286
I did some research using an Android Wear watch, Samsung Gear S2, random heart rate fitness tracker watch (Ticwatch) and a standalone bluetooth heart rate arm band.
Just to reiterate my goal was to read heart rate data from the watch's sensor through my phone app without making a watch app.
My findings were as follows:
I hope this clarifies how the SensorManager only works for sensors on the device the app is running on.
Upvotes: 7
Reputation: 13469
Based from these posts 1 and 2, make sure that your application has defined and granted the Body Sensors permission.
Verify that:
<uses-permission android:name="android.permission.BODY_SENSORS"/>
is present in your wear AndroidManifest.xml
Also, ensure that the permission has been granted by checking the Permissions settings on the watch: Settings -> Permissions -> Your app
You may check this GitHub link for example.
Upvotes: 0