Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

7. Many Devices, One Application > Limiting Access to Your App to Devices That ...

Limiting Access to Your App to Devices That Work

Your Android application may, in a lot of cases, require some very specific hardware in order to work correctly. I imagine that users who, for example, download a camera app to a device that doesn’t have a camera will have a very poor experience.

The <uses> Tag

Android gives you an avenue to tell the marketplace which devices it should allow to download and purchase your application. This is done with the <uses> tag in your AndroidManifest.xml file.

If, for example, your app requires the device to have a camera, you should add the following line to your manifest:

<uses-feature android:name="android.hardware.camera"
    android:required="true"/>

This line tells Android that the application should not be installed on a device without a camera, because it’s required for correct operation. You can, on the flip side, declare that your app use a particular piece of hardware, but degrade appropriately if it’s not there. An image-editing app might want the camera, but if the camera’s not there it may still function by modifying images saved from the web in the device’s built-in gallery. You tell the system this by declaring the hardware as used but setting the requirement to false:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint