O'Reilly logo

Mastering Android Studio 3 by Kyle Mew

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Accessing sensors

Devices worn on the wrist are ideal for fitness apps and the inclusion of a heart rate monitor in many models makes them perfect for such tasks. The way that the SDK manages all sensors is almost identical, so seeing how one works applies to the others.

The following exercise demonstrates how to read the heart rate sensor on a wearable device:

  1. Open an Android Wear project with both mobile and wear modules.
  2. Create a layout of your choosing, ensuring you include a TextView to display the output.

 

  1. Open the Manifest file in the wear module and add the following permission:
<uses-permission     android:name="android.permission.BODY_SENSORS" /> 
  1. Open the MainActivity.java file in the wear module and add the following fields: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required