Hardware Interface

^Android devices have multiple different types of hardware that are built in and accessible to developers. Sensors, such as a camera, accelerometer, magnetometer, pressure sensor, temperature sensor, and proximity sensor, are available on most devices.Telephony, Bluetooth, and other wireless connections are also accessible to the developer in some form. This chapter shows how to leverage these hardware Application Programming Interfaces (API) to enrich an application's experience. Note that these recipes are best run on actual Android devices because the emulator might not provide accurate or realistic behavior of hardware interfaces.

The camera is the most visible and most used sensor in an Android device. It is a selling point for most consumers, and the capabilities are getting better with each generation. Image-processing applications normally work on an image after it is taken, but other applications, such as augmented reality, utilize the camera in real-time with overlays.

There are two ways to access the camera from an application. The first is by declaring an implicit intent as described in Chapter 2,'Application Basics:Activities and Intents." The implicit intent launches the default camera interface:

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivity(intent);

The second way leverages the Camera class, which provides more flexibility in the settings.This creates a custom camera interface, which is the focus of the examples that follow. Camera hardware access requires explicit permission in the AndroidManifest

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook

Post a comment