Hardware Tools

Google exposes a plethora of functionality in Android, thus giving developers (even the independent guys) the tools needed to create top-notch, full-featured mobile apps. Google has gone above and beyond by making it simple to tap into and make use of all the devices' available hardware.

To create a spectacular Android app, you should take advantage of all that the hardware has to offer. Don't get me wrong: If you have an idea for an app that doesn't need hardware assistance, that's okay too.

Android devices come with several hardware features that you can use to build your apps, as shown in Table 1-1.

Table 1-1 Android Device Hardware

To Get This Functionality… …Use This Hardware Feature
Determine the location of the tablet/device GPS radio
Determine the direction the tablet/device is moving Built-in compass
Determine whether the tablet/device is facing up or down Proximity sensor
Determine whether the tablet/device is moving Accelerometer
Use Bluetooth headphones Bluetooth radio
Record video Camera
Read NFC tags Near Field Communication

Most Android devices are released with the hardware that I discuss in the following sections, but not all devices are created equal. Because Android is free for hardware manufacturers to distribute, it's used in a wide range of devices, including some made by small manufacturers overseas — and it's not uncommon for some of these phones to be missing a feature or two.

Also, as the technology advances, device manufacturers are starting to add features that aren't yet natively supported by Android. Don't worry too much, though, because manufacturers that add hardware usually offer a software development kit (SDK) that lets developers tap into the device's unique feature. For example, as of this writing, only a few devices have come with a front-facing camera. Because these devices are the first of their kind, the device manufacturers have released an SDK that developers can use to access this cool new feature, as well as sample code that lets them implement the feature easily.

image Android devices come in all shapes and sizes: phones, tablet computers, and e-book readers. You will find many other implementations of Android in the future, such as Google TV (an Android-powered home appliance) as well as cars with built-in, Android-powered, touchscreen computers. The engineers behind Android provide tools that let you easily deploy apps for multiple screen sizes and resolutions. Indeed, the Android team has done all the hard work for you.

Touchscreen

Android phones have touchscreens, a fact that opens a ton of possibilities and can enhance users' interaction with your apps. Users can swipe, flip, drag, and pinch to zoom by moving a finger or fingers on the touchscreen. You can even use custom gestures for your app, which opens even more possibilities.

Android also supports multitouch, which means that the entire screen is touchable by more than one finger at a time.

image Hardware buttons are old news. You can place buttons of any shape anywhere on the screen to create the UI that's best suited for your app.

GPS

The Android OS combined with a phone's GPS radio allows developers to access a user's location at any given moment. You can track a user's movement as she changes locations. The social networking app from foursquare is a good example; it uses GPS to determine the phone's location and then accesses the web to determine which establishment or public place the user is in or near.

Another great example is the Maps application's ability to pinpoint your location on a map and provide directions to your destination. Android combined with GPS hardware gives you access to the phone's exact GPS location. Many apps use this functionality to show you where the nearest gas station, coffeehouse, or even restroom is located. You can even use the Maps application's API to pinpoint the user's current location on a map.

Accelerometer

Android comes packed with accelerometer support. An accelerometer is a device that measures acceleration. That sounds cool and all, but what can you do with it? Well, if you want to know whether the phone is moving or being shaken, or even the direction in which it's being turned, the accelerometer can tell you.

You may be thinking, “Okay, but why do I care whether the phone is being shaken or turned?” Simple! You can use that input as a way to control your application. You can do simple things like determine whether the phone has been turned upside down and do something when that happens. Maybe you're making a dice game and want to immerse your users in the game play by having them shake the phone to roll the dice. This is the kind of functionality that's setting mobile devices apart from typical desktop personal computers.

SD Card

Android gives you the tools you need to access (save and load) files on the device's SD Card, a portable storage medium that you can insert into various phones, tablets, and computers. If a device is equipped with an SD Card, you can use it to store and access files needed by your application. As of Android 2.2, you could install apps on the SD Card. However, if your users have phones that don't get Android 2.2, you're not sunk. Just because some users don't have the option of installing apps on the SD Card doesn't mean that you have to bloat your app with 20 MB of resources and hog the phone's limited built-in memory. You can download some or all of your application's resources from your web host and save them to the phone's SD Card. This makes your users happy and less likely to uninstall your app when space is needed.

image Not all devices come with an SD Card installed, although most do. Always make sure that the user has an SD Card installed and that adequate space is available before trying to save files to it, though.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.247.16