Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Android Studio 3

You're reading from   Mastering Android Studio 3 Build Dynamic and Robust Android applications

Arrow left icon
Product type Paperback
Published in Aug 2017
Publisher
ISBN-13 9781786467447
Length 220 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Kyle Mew Kyle Mew
Author Profile Icon Kyle Mew
Kyle Mew
Arrow right icon
View More author details
Toc

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 chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime