Chapter 8

Programming with the Device Hardware

What's in This Chapter?

  • Using the sensor API
  • Programming accelerometer, device orientation, and proximity detection support
  • Supporting networking
  • Bluetooth programming

Android contains a vast amount of exciting hardware. This hardware in and of itself doesn't interest users; the excitement occurs when the application presents the users with information in a way that makes sense to them. This hardware is very interesting to developers building apps because it allows applications to provide extraordinary features based on it. This chapter looks at the sensor API, accelerometer, device orientation, proximity detection, networking, and Bluetooth. Here are some sample uses of this hardware:

  • A program can test whether a network is available over any connection (WiFi, 3G, or EDGE). If a connection does not exist, instead of seeing an error message when attempting to upload information, the user can be notified that there is no connection to a service.
  • The accelerometer can be used to pull random data from a data source. When the device is shaken, the application can respond by reading random data from a data source.
  • When the user changes the device from portrait to landscape, the application can change how it displays content to the user.

Working with Sensors

Android devices come with all types of exciting features, including accelerometers, compasses, microphones, gyroscopes, and other nifty hardware. This hardware allows devices to ...

Get Professional Android Programming with Mono for Android and .NET/C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.