1page.title=Device Compatibility
2excludeFromSuggestions=true
3@jd:body
4
5<div id="qv-wrapper">
6<div id="qv">
7<h2>In this document</h2>
8<ol>
9  <li><a href="#defined">What Does "Compatibility" Mean?</a></li>
10  <li><a href="#how">Controlling Your App's Availability to Devices</a>
11    <ol>
12      <li><a href="#Features">Device features</a></li>
13      <li><a href="#Versions">Platform version</a></li>
14      <li><a href="#Screens">Screen configuration</a></li>
15    </ol>
16  </li>
17  <li><a href="#filtering">Controlling Your App's Availability for Business Reasons</a></li>
18</ol>
19
20<h2>See also</h2>
21 <ol>
22<li><a
23href="{@docRoot}google/play/filters.html">Filtering on Google Play</a></li>
24<li><a
25href="{@docRoot}guide/topics/resources/providing-resources.html">Providing Resources</a></li>
26<li><a href="http://source.android.com/compatibility/index.html" class="external-link">
27Android Compatibility</a></li>
28</ol>
29
30
31</div> </div>
32
33<p>Android is designed to run on many different types of devices, from phones
34to tablets and televisions. As a developer,
35the range of devices provides a huge potential audience for your app. In order for your app
36to be successful on all these devices, it should tolerate some feature variability
37and provide a flexible user interface that adapts to different screen
38configurations.</p>
39
40<p>To facilitate your effort toward that goal, Android provides a dynamic app framework in which
41you can provide configuration-specific <a href="{@docRoot}guide/topics/resources/overview.html"
42>app resources</a> in static files (such as different XML layouts
43for different screen sizes). Android then loads the appropriate resources based on
44the current device configuration. So with some forethought to your app design and some additional
45app resources, you can publish a single application package (APK) that provides an optimized user
46experience on a variety of devices.
47
48<p>If necessary, however, you can specify your app's feature requirements and control
49which types of devices can install your app from Google Play Store. This page explains how you can
50control which devices have access to your apps, and how to prepare your apps to make sure they
51reach the right audience. For more information about how you can make your app adapt
52to different devices, read <a href="{@docRoot}training/basics/supporting-devices/index.html"
53>Supporting Different Devices</a>.</p>
54
55
56
57<h2 id="defined">What Does "Compatibility" Mean?</h2>
58
59<p>As you read more about Android development, you'll probably encounter the term "compatibility"
60in various situations. There are two types of compatibility: <em>device compatibility</em>
61and <em>app compatibility</em>.
62
63<p>Because Android is an open source project, any hardware manufacturer can build a device
64that runs the Android operating system. Yet, a <b>device is "Android compatible"</b> only if
65it can correctly run apps written for the
66<em>Android execution environment</em>. The exact details of the Android execution
67environment are defined by the <a href="http://source.android.com/compatibility/overview.html"
68class="external-link">Android compatibility program</a> and each device must pass the Compatibility
69Test Suite (CTS) in order to be considered compatible.</p>
70
71<p>As an app developer, you don't need to worry about whether a device is Android compatible, because
72only devices that are Android compatible include Google Play Store. So you can rest assured that
73users who install your app from Google Play Store are using an Android compatible device.</p>
74
75
76<p>However, you do need to consider whether your <b>app is compatible</b> with each potential
77device configuration. Because Android runs on a wide range of device configurations, some features are not
78available on all devices. For example, some devices may not include a
79compass sensor. If your app's core functionality requires the use
80of a compass sensor, then your app is compatible only with devices that
81include a compass sensor.</p>
82
83
84
85
86<h2 id="how">Controlling Your App's Availability to Devices</h2>
87
88<p>Android supports a variety of features your app can leverage through platform APIs. Some
89features are hardware-based (such as a compass sensor), some are software-based (such as app
90widgets), and some are dependent on the platform version. Not every device supports every feature,
91so you may need to control your app's availability to devices based on your app's required
92features.</p>
93
94
95<p>To achieve the largest user-base possible for your app, you should strive to support as many
96device configurations as possible using a single APK. In most situations, you can do so by
97disabling optional features at runtime and <a
98href="{@docRoot}guide/topics/resources/providing-resources.html">providing app resources</a>
99with alternatives for different configurations (such as different layouts for different
100screen sizes).
101If necessary, however, you can restrict your app's availability to devices through Google Play
102Store based on the following device characteristics:</p>
103
104<ul>
105  <li><a href="#Features">Device features</a>
106  <li><a href="#Version">Platform version</a>
107  <li><a href="#Screens">Screen configuration</a>
108</ul>
109
110
111<h3 id="Features">Device features</h3>
112
113<p>In order for you to manage your app’s availability based on device features,
114Android defines <em>feature IDs</em> for any hardware or software feature
115that may not be available on all devices. For instance, the
116feature ID for the compass sensor is {@link
117android.content.pm.PackageManager#FEATURE_SENSOR_COMPASS} and the feature ID for app widgets
118is {@link android.content.pm.PackageManager#FEATURE_APP_WIDGETS}.</p>
119
120<p>If necessary, you can prevent users from installing your app when their devices don't provide a
121given feature by declaring it with a <a href=
122"{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code &lt;uses-feature&gt;}</a>
123element in your app's <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">manifest
124file</a>.</p>
125
126<p>For example, if your app does not make sense on a device that lacks a compass sensor,
127you can declare the compass sensor as required with the following manifest tag:</p>
128
129<pre>
130&lt;manifest ... >
131    &lt;uses-feature android:name="android.hardware.sensor.compass"
132                  android:required="true" />
133    ...
134&lt;/manifest>
135</pre>
136
137<p>Google Play Store compares the features your app requires to the features available on
138each user's device to determine whether your app is compatible with each device.
139If the device does not provide all the features your app requires, the user cannot install
140your app.</p>
141
142<p>However, if your app's primary functionality does not <em>require</em>
143a device feature, you should set the <a href=
144"{@docRoot}guide/topics/manifest/uses-feature-element.html#required">{@code required}</a>
145attribute to {@code "false"} and check
146for the device feature at runtime. If the app feature is not available on the current device,
147gracefully degrade the corresponding app feature. For example, you can query whether
148a feature is available by calling
149{@link android.content.pm.PackageManager#hasSystemFeature hasSystemFeature()} like this:</p>
150
151<pre>
152PackageManager pm = getPackageManager();
153if (!pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) {
154    // This device does not have a compass, turn off the compass feature
155    disableCompassFeature();
156}
157</pre>
158
159<p>For information about all the filters you can
160use to control the availability of your app to users through Google Play Store, see the
161<a href="{@docRoot}google/play/filters.html">Filters on Google Play</a>
162document.</p>
163
164<p class="note"><strong>Note:</strong> Some <a href=
165"{@docRoot}guide/topics/security/permissions.html">system permissions</a> implicitly require the
166availability of a device feature. For example, if your app requests permission to access to {@link
167android.Manifest.permission#BLUETOOTH}, this implicitly requires the {@link
168android.content.pm.PackageManager#FEATURE_BLUETOOTH} device feature. You can disable filtering based
169on this feature and make your app available to devices without Bluetooth by setting the <a href=
170"{@docRoot}guide/topics/manifest/uses-feature-element.html#required">{@code required}</a> attribute
171to {@code "false"} in the <a href=
172"{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code &lt;uses-feature&gt;}</a> tag.
173For more information about implicitly required device features, read <a href=
174"{@docRoot}guide/topics/manifest/uses-feature-element.html#permissions">Permissions that Imply
175Feature Requirements</a>.</p>
176
177
178
179
180
181
182
183<h3 id="Versions">Platform version</h3>
184
185<p>Different devices may run different versions of the Android platform,
186such as Android 4.0 or Android 4.4. Each successive platform version often adds new APIs not
187available in the previous version. To indicate which set of APIs are available, each
188platform version specifies an <a
189href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">API level</a>. For instance,
190Android 1.0 is API level 1 and Android 4.4 is API level 19.</p>
191
192<p>The API level allows you to declare the minimum version with which your app is
193compatible, using the <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">{@code
194&lt;uses-sdk>}</a> manifest tag and its <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a> attribute.</p>
195
196<p>For example, the <a href="{@docRoot}guide/topics/providers/calendar-provider.html">Calendar
197Provider</a> APIs were added in Android 4.0 (API level 14). If your app cannot function without
198these APIs, you should declare API level 14 as your app's minimum supported
199version like this:</p>
200
201<pre>
202&lt;manifest ... >
203    &lt;uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
204    ...
205&lt;/manifest>
206</pre>
207
208<p>The <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code
209minSdkVersion}</a> attribute declares the minimum version with which your app is compatible
210and the <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
211targetSdkVersion}</a> attribute declares the highest version on which you've optimized
212your app.</p>
213
214<p>Each successive version of Android provides compatibility for apps that were built using
215the APIs from previous platform versions, so your app should always be compitible with future
216versions of Android while using the documented Android APIs.</p>
217
218<p class="note"><strong>Note:</strong>
219The <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
220targetSdkVersion}</a> attribute does not prevent your app from being installed on platform
221versions that are higher than the specified value,
222but it is important because it indicates to the system whether your
223app should inherit behavior changes in newer versions. If you don't update the
224<a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
225targetSdkVersion}</a> to the latest version, the system assumes that your
226app requires some backward-compatibility behaviors when running on the latest version.
227For example, among the <a href="{@docRoot}about/versions/android-4.4.html#Behaviors"
228>behavior changes in Android 4.4</a>, alarms created with the {@link android.app.AlarmManager} APIs
229are now inexact by default so the system can batch app alarms and preserve system power,
230but the system will retain the previous API behavior for your app if your target API level
231is lower than "19".</p>
232
233<p>However, if your app uses APIs added in a more recent
234platform version, but does not require them for its primary functionality,
235you should check the API level at runtime and gracefully degrade
236the corresponding features when the API level is too low. In this case,
237set the <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code
238minSdkVersion}</a> to the lowest value possible for your app's primary functionality,
239then compare the current system's version, {@link android.os.Build.VERSION#SDK_INT}, to one the
240codename constants in {@link android.os.Build.VERSION_CODES} that corresponds to the
241API level you want to check. For example:</p>
242
243<pre>
244if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
245    // Running on something older than API level 11, so disable
246    // the drag/drop features that use {@link android.content.ClipboardManager} APIs
247    disableDragAndDrop();
248}
249</pre>
250
251
252
253
254
255
256<h3 id="Screens">Screen configuration</h3>
257
258<p>Android runs on devices of various sizes, from phones to tablets and TVs.
259In order to categorize devices by their screen type, Android defines two characteristics for
260each device: screen size (the physical size of the screen) and screen density (the physical
261density of the pixels on the screen, known as <acronym title="dots per inch">DPI</acronym>).
262To simplify the different configurations, Android generalizes these variants into groups that make
263them easier to target:</p>
264
265<ul>
266  <li>Four generalized sizes: small, normal, large, and xlarge.</li>
267  <li>And several generalized densities: mdpi (medium), hdpi (hdpi), xhdpi (extra high),
268  xxhdpi (extra-extra high), and others.</li>
269</ul>
270
271<p>By default, your app is compatible with all screen sizes and densities,
272because the system makes the appropriate adjustments to your UI layout and image
273resources as necessary for each screen. However, you should optimize the user experience for each
274screen configuration by adding specialized layouts for different screen sizes and
275optimized bitmap images for common screen densities.</p>
276
277<p>For information about how to create alternative resources for different screens
278and how to restrict your app to certain screen sizes when necessary, read <a
279href="{@docRoot}training/basics/supporting-devices/screens.html">Supporting Different Screens</a>.
280</p>
281
282
283
284
285
286
287
288
289<h2 id="filtering">Controlling Your App's Availability for Business Reasons</h2>
290
291<p>In addition to restricting your app's availability based on device characteristics,
292it’s possible you may need to restrict your app’s availability for
293business or legal reasons. For instance, an app that displays train schedules
294for the London Underground is unlikely to be useful to users outside the United
295Kingdom. For this type of situation, Google Play Store provides
296filtering options in the developer console that allow you to control your app’s
297availability for non-technical reasons such as the user's locale or wireless carrier.</p>
298
299<p>Filtering for technical compatibility (such as required hardware components)
300is always based on information contained within your APK file. But
301filtering for non-technical reasons (such as geographic locale) is always
302handled in the Google Play developer console.</p>
303
304
305
306
307
308
309<div class="next-docs">
310<div class="col-6">
311  <h2 class="norule">Continue reading about:</h2>
312  <dl>
313    <dt><a
314href="{@docRoot}guide/topics/resources/providing-resources.html">Providing Resources</a></dt>
315    <dd>Information about how Android apps are structured to separate app resources from the
316   app code, including how you can provide alternative resources for specific device
317   configurations.
318    </dd>
319    <dt><a href="{@docRoot}google/play/filters.html">Filters on Google Play</a></dt>
320    <dd>Information about the different ways that Google Play Store can prevent your app
321   from being installed on different devices.</dd>
322  </dl>
323</div>
324<div class="col-6">
325  <h2 class="norule">You might also be interested in:</h2>
326  <dl>
327    <dt><a href="{@docRoot}guide/topics/security/permissions.html"
328        >System Permissions</a></dt>
329    <dd>How Android restricts app access to certain APIs with a permission system that requires
330  the user's consent for your app to use those APIs.</dd>
331  </dl>
332</div>
333</div>
334