Reader small image

You're reading from  Mastering Android Studio 3

Product typeBook
Published inAug 2017
Reading LevelIntermediate
Publisher
ISBN-139781786467447
Edition1st Edition
Languages
Right arrow
Author (1)
Kyle Mew
Kyle Mew
author image
Kyle Mew

Kyle Mew has been programming since the early '80s and has written for several technology websites. Also, he has written three radio plays and four other books on Android development.
Read more about Kyle Mew

Right arrow

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:
private TextView textView; 
private SensorManager sensorManager;
private Sensor sensor;
  1. Have the Activity implement a...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering Android Studio 3
Published in: Aug 2017Publisher: ISBN-13: 9781786467447

Author (1)

author image
Kyle Mew

Kyle Mew has been programming since the early '80s and has written for several technology websites. Also, he has written three radio plays and four other books on Android development.
Read more about Kyle Mew