Android is designed to run on many different types of devices. For developers, the range and number of devices means a huge potential audience: the more devices that run Android apps, the more users who can access your app. In exchange, however, it also means that your apps will have to cope with that same variety of hardware.
Fortunately, Android has built-in tools and support that make it easy for your apps to do that, while at the same time letting you maintain control of what types of devices your app is available to. With a bit of forethought and some minor changes in your app's manifest file, you can ensure that users whose devices can’t run your app will never see it in the Android Market, and will not get in trouble by downloading it. This page explains how you can control which devices have access to your apps, and how to prepare your apps to make sure they reach the right audience.
A device is “Android compatible” if it can correctly run apps written for the
Android execution environment. The exact details of the Android execution
environment are defined by the Android Compatibility Definition Document,
but the single most important characteristic of a compatible device is the
ability to install and correctly run an Android .apk
file.
There is exactly one Android API for each API level, and it’s the same API no matter what kind of device it’s installed on. No parts of the API are optional, and you never have to worry about parts of the API missing on some devices. Every compatible Android device your app will land on will include every class and every API for that API level.
Of course, some APIs won’t work correctly if a particular device lacks the corresponding hardware or feature. But that’s not a problem: we also designed Android to prevent apps from being visible to devices which don’t have features the apps require. We’ve built support for this right into the SDK tools, and it’s part of the Android platform itself, as well as Android Market.
As a developer, you have complete control of how and where your apps are available. Android provides tools as a first-class part of the platform that let you manage this. You control the availability of your apps, so that they reach only the devices capable of running them.
You manage your app’s availability through a simple three-step process:
<uses-feature>
elements its manifest file.This way, users never even see apps that won’t work properly on their devices. As long as you accurately describe your app’s requirements, you don’t need to worry about users blaming you for compatibility problems.
If you’re familiar with web development, you may recognize this model as “capability detection”. Web developers typically prefer this approach to “browser detection”, because it’s very difficult to keep up as new browsers and new versions of current browsers are released. By checking for support for specific required capabilities instead of the current browser, web developers get better fine-grained control. That’s the same approach Android uses: since it’s impossible to keep up with all the Android devices being released, you instead use the fine-grained controls Android provides.
Filtering on Android Market
Android Market filters the applications that are visible to users, so that users can see and download only those applications that are compatible with their devices.
One of the ways Market filters applications is by
feature compatibility. To do this, Market checks the
<uses-feature>
elements in each application's manifest, to
establish the app's feature needs. Market then shows or hides the application to
each user, based on a comparison with the features available on the user's
device.
For information about other filters that you can use to control the availability of your apps, see the Market Filters document.
Android includes support for a lot of features, some hardware and some software. Examples include compass and accelerometer sensors, cameras, and Live Wallpapers. However, not every device will support every feature. For instance, some devices don’t have the hardware horsepower to display Live Wallpapers well.
To manage this, Android defines feature IDs. Every capability has a
corresponding feature ID defined by the Android platform. For instance, the
feature ID for compass is “android.hardware.sensor.compass”
,
while the feature
ID for Live Wallpapers is “android.software.live_wallpapers”
. Each of these IDs
also has a corresponding Java-language constant on the
PackageManager
class that you can use to query whether
feature is supported at runtime. As Android adds support for new features in
future versions, new feature IDs will be added as well.
When you write your application, you specify which features your app requires
by listing their feature IDs in <uses-feature>
elements in
the AndroidManifest.xml
file. This is the information that Android
Market uses to match your app to devices that can run it. For instance, if you
state that your app requires android.software.live_wallpapers, it won’t be shown
to devices that don’t support Live Wallpapers.
This puts you in total control of your app — because you don’t have to declare these features. Consider an example involving cameras.
If you’re building a really impressive next-generation augmented-reality app, your app won’t function at all without a camera. However, if you’re building a shopping app that only uses the camera for barcode scanning, users without cameras might still find it useful even if they can’t scan barcodes. While both apps need to acquire the permission to access the camera, only the first app needs to state that it requires a camera. (The shopping app can simply check at runtime and disable the camera-related features if there’s no camera present.)
Since only you can say what the best approach is for your app, Android provides the tools and lets you make your own tradeoff between maximizing audience size and minimizing development costs.
It’s possible that you may need to restrict your app’s availability for business or legal reasons. For instance, an app that displays train schedules for the London Underground is unlikely to be useful to users outside the United Kingdom. Other apps might not be permitted in certain countries for business or legal reasons. For cases such as these, Android Market itself provides developers with filtering options that allow them control their app’s availability for non-technical reasons.
The help information for Android Market provides full details, but in a nutshell, developers can use the Market publisher UI to:
Filtering for technical compatibility (such as required hardware components)
is always based on information contained within your .apk
file. But
filtering for non-technical reasons (such as geographic restrictions) is always
handled in the Market user interface.
There’s one additional quirk that we haven’t yet addressed: protecting apps from changes made to future versions of Android. If the Android platform introduces a new feature or changes how existing features are handled, what happens to existing apps that were written without any knowledge of the new behavior?
Simply put, Android commits to not making existing apps available to devices where they won’t work properly, even when the platform changes. The best way to explain this is through examples, so here are two:
In other words, whenever Android introduces new features or changes existing ones, we will always take steps to protect existing applications so that they don’t end up being available to devices where they won’t work.
This is implemented, in part, using the aapt
tool in the SDK.
To see which features your app explicitly requires or is implicitly assumed to
require, you can use the command aapt dump badging
.
The goal of Android is to create a huge installed base for developers to take advantage of. One of the ways we will achieve this is through different kinds of hardware running the same software environment. But we also recognize that only developers know which kinds of devices their apps make sense on. We’ve built in tools to the SDK and set up policies and requirements to ensure that developers remain in control of their apps, today and in the future. With the information you just read, and the resources listed in the sidebar of this document, you can publish your app with the confidence that only users who can run it will see it.
For more information about Android device compatibility, please visit: