Interacting with Device Hardware Android

The Android platform allows unprecedented access to the device’s underlying hardware in a secure and robust manner. Because not all Android devices support or contain all hardware options, it is very important to follow these guidelines when accessing underlying device hardware:

  • Make no assumptions about the existence or availability of underlying hardware in code or otherwise.
  • Always check and verify optional features before trying to access hardware programmatically.
  • Pay special attention to exception handling as well as error and return value checking when working with hardware APIs.
  • Understand that hardware features are device resources. Acquire them late, and release them as soon as you’re done. In other words, play nice with the other apps. Don’t hog the hardware or drain the device battery by misusing hardware resources.

The optional hardware features of different Android devices are key market differentiators to consumers. For example, some might want a device that can act as a Wi-Fi hotspot. Others might require Bluetooth. Still others might be interested in the data that can be collected from various sensors on the device. Finally, applications can access data about the battery and the power management state. Also recall that we talked about other hardware related features, such as the camera and location-based services, in Chapter “Using Location-Based Services (LBS) APIs,” and Chapter “Using Android Multimedia APIs,” respectively.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Android Topics