blob: 8f7ac558593601155bb440985fd336b59f81b315 [file] [log] [blame]
Scott Main1d6f70c2011-10-06 22:57:25 -07001page.title=Android 4.0 Platform
2sdk.platform.version=4.0
3sdk.platform.apiLevel=14
4@jd:body
5
6<div id="qv-wrapper">
7<div id="qv">
8
9<h2>In this document</h2>
10<ol>
11 <li><a href="#relnotes">Revisions</a></li>
12 <li><a href="#api">API Overview</a></li>
13 <li><a href="#api-diff">API Differences Report</a></li>
14 <li><a href="#api-level">API Level</a></li>
15 <li><a href="#apps">Built-in Applications</a></li>
16 <li><a href="#locs">Locales</a></li>
17 <li><a href="#skins">Emulator Skins</a></li>
18</ol>
19
20<h2>Reference</h2>
21<ol>
22<li><a
23href="{@docRoot}sdk/api_diff/14/changes.html">API
24Differences Report &raquo;</a> </li>
25</ol>
26
27</div>
28</div>
29
30
31<p><em>API Level:</em>&nbsp;<strong>{@sdkPlatformApiLevel}</strong></p>
32
33<p>Android 4.0 (Ice Cream Sandwich) is a major platform release that adds new
34capabilities for users and developers. The sections below provide an overview
35of the new features and developer APIs.</p>
36
37<p>For developers, the Android {@sdkPlatformVersion} platform is available as a
38downloadable component for the Android SDK. The downloadable platform includes
39an Android library and system image, as well as a set of emulator skins and
40more. The downloadable platform includes no external libraries.</p>
41
42<p>To start developing or testing against Android {@sdkPlatformVersion},
43use the Android SDK Manager to download the platform into your SDK. For more
44information, see <a href="{@docRoot}sdk/adding-components.html">Adding SDK
45Components</a>. If you are new to Android, <a
46href="{@docRoot}sdk/index.html">download the SDK Starter Package</a> first.</p>
47
48<p>For a high-level introduction to the new user and developer features in Android 4.0, see the
49<a href="http://developer.android.com/sdk/android-4.0-highlights.html">Platform Highlights</a>.</p>
50
51<p class="note"><strong>Reminder:</strong> If you've already published an
52Android application, please test your application on Android {@sdkPlatformVersion} as
53soon as possible to be sure your application provides the best
54experience possible on the latest Android-powered devices.</p>
55
56
57<h2 id="relnotes">Revisions</h2>
58
59<p>To determine what revision of the Android {@sdkPlatformVersion} platform you
60have installed, refer to the "Installed Packages" listing in the Android SDK Manager.</p>
61
62
63<div class="toggle-content opened" style="padding-left:1em;">
64
65 <p><a href="#" onclick="return toggleContent(this)">
66 <img src="{@docRoot}assets/images/triangle-opened.png"
67class="toggle-content-img" alt="" />
68 Android {@sdkPlatformVersion}, Revision 1</a> <em>(October 2011)</em>
69 </a></p>
70
71 <div class="toggle-content-toggleme" style="padding-left:2em;">
72
73<dl>
74<dt>Initial release. SDK Tools r14 or higher is recommended.</dt>
75</dl>
76
77 </div>
78</div>
79
80
81<h2 id="api">API Overview</h2>
82
83<p>The sections below provide a technical overview of new APIs in Android 4.0.</p>
84
85<div class="toggle-content closed" style="padding-left:1em;">
86
87 <p><a href="#" onclick="return toggleContent(this)">
88 <img src="{@docRoot}assets/images/triangle-closed.png"
89class="toggle-content-img" alt="" />
90 <strong>Table of Contents</strong>
91 </a></p>
92
93 <div class="toggle-content-toggleme" style="padding-left:2em;">
94 <ol class="toc" style="margin-left:-1em">
95 <li><a href="#Contacts">Contacts</a></li>
96 <li><a href="#Calendar">Calendar</a></li>
97 <li><a href="#Camera">Camera</a></li>
98 <li><a href="#Multimedia">Multimedia</a></li>
99 <li><a href="#Bluetooth">Bluetooth</a></li>
100 <li><a href="#AndroidBeam">Android Beam (NDEF Push with NFC)</a></li>
101 <li><a href="#P2pWiFi">Peer-to-peer Wi-Fi</a></li>
102 <li><a href="#NetworkData">Network Data</a></li>
103 <li><a href="#Sensors">Device Sensors</a></li>
104 <li><a href="#Renderscript">Renderscript</a></li>
105 <li><a href="#A11y">Accessibility</a></li>
106 <li><a href="#Enterprise">Enterprise</a></li>
107 <li><a href="#Voicemail">Voicemail</a></li>
108 <li><a href="#SpellChecker">Spell Checker Services</a></li>
109 <li><a href="#TTS">Text-to-speech Engines</a></li>
110 <li><a href="#ActionBar">Action Bar</a></li>
111 <li><a href="#UI">User Interface and Views</a></li>
112 <li><a href="#Properties">Properties</a></li>
113 <li><a href="#HwAccel">Hardware Acceleration</a></li>
114 <li><a href="#Jni">JNI Changes</a></li>
115 <li><a href="#WebKit">WebKit</a></li>
116 <li><a href="#Permissions">Permissions</a></li>
117 <li><a href="#DeviceFeatures">Device Features</a></li>
118 </ol>
119 </div>
120</div>
121
122
123
124
125
126<h3 id="Contacts">Contacts</h3>
127
128<p>The Contact APIs that are defined by the {@link android.provider.ContactsContract} provider have
129been extended to support new features such as a personal profile for the device owner, large contact
130photos, and the ability for users to invite individual contacts to social networks that are
131installed on the device.</p>
132
133
134<h4>User Profile</h4>
135
136<p>Android now includes a personal profile that represents the device owner, as defined by the
137{@link
138android.provider.ContactsContract.Profile} table. Social apps that maintain a user identity can
139contribute to the user's profile data by creating a new {@link
140android.provider.ContactsContract.RawContacts} entry within the {@link
141android.provider.ContactsContract.Profile}. That is, raw contacts that represent the device user do
142not belong in the traditional raw contacts table defined by the {@link
143android.provider.ContactsContract.RawContacts} Uri; instead, you must add a profile raw contact in
144the table at {@link android.provider.ContactsContract.Profile#CONTENT_RAW_CONTACTS_URI}. Raw
145contacts in this table are then aggregated into the single user-visible profile information.</p>
146
147<p>Adding a new raw contact for the profile requires the {@link
148android.Manifest.permission#WRITE_PROFILE} permission. Likewise, in order to read from the profile
149table, you must request the {@link android.Manifest.permission#READ_PROFILE} permission. However,
150reading the user profile should not be required by most apps, even when contributing data to the
151profile. Reading the user profile is a sensitive permission and users will be very skeptical of apps
152that request reading their profile information.</p>
153
154<h4>Large photos</h4>
155
156<p>Android now supports high resolution photos for contacts. Now, when you push a photo into a
157contact
158record, the system processes it into both a 96x96 thumbnail (as it has previously) and a 256x256
159"display photo" stored in a new file-based photo store (the exact dimensions that the system chooses
160may vary in the future). You can add a large photo to a contact by putting a large photo in the
161usual {@link android.provider.ContactsContract.CommonDataKinds.Photo#PHOTO} column of a data row,
162which the system will then process into the appropriate thumbnail and display photo records.</p>
163
164<h4>Invite Intent</h4>
165
166<p>The {@link android.provider.ContactsContract.Intents#INVITE_CONTACT} intent action allows you to
167invoke an action that indicates the user wants to add a contact to a social network that understand
168this intent and use it to invite the contact specified in the contact to that social network.</p>
169
170<p>Apps that use a sync adapter to provide information about contacts can register with the system
171to
172receive the invite intent when there’s an opportunity for the user to “invite” a contact to the
173app’s social network (such as from a contact card in the People app). To receive the invite intent,
174you simply need to add the {@code inviteContactActivity} attribute to your app’s XML sync
175configuration file, providing a fully-qualified name of the activity that the system should start
176when the user wants to “invite” a contact in your social network. The activity that starts can then
177retrieve the URI for the contact in question from the intent’s data and perform the necessary work
178to
179invite that contact to the network or add the person to the user’s connections.</p>
180
181<h4>Contact Usage Feedback</h4>
182
183<p>The new {@link android.provider.ContactsContract.DataUsageFeedback} APIs allow you to help track
184how often the user uses particular methods of contacting people, such as how often the user uses
185each phone number or e-mail address. This information helps improve the ranking for each contact
186method associated with each person and provide such contact methods as suggestions.</p>
187
188
189
190
191
192<h3 id="Calendar">Calendar</h3>
193
194<p>The new calendar API allows you to access and modify the user’s calendars and events. The
195calendar
196APIs are provided with the {@link android.provider.CalendarContract} provider. Using the calendar
197provider, you can:</p>
198<ul>
199<li>Read, write, and modify calendars.</li>
200<li>Add and modify events, attendees, reminders, and alarms.</li>
201</ul>
202
203<p>{@link android.provider.CalendarContract} defines the data model of calendar and event-related
204information. All of the user’s calendar data is stored in a number of tables defined by subclasses
205of {@link android.provider.CalendarContract}:</p>
206
207<ul>
208<li>The {@link android.provider.CalendarContract.Calendars} table holds the calendar-specific
209information. Each row in this table contains the details for a single calendar, such as the name,
210color, sync information, and so on.</li>
211
212<li>The {@link android.provider.CalendarContract.Events} table holds event-specific information.
213Each
214row in this table has the information for a single event. It contains information such as event
215title, location, start time, end time, and so on. The event can occur one-time or can recur multiple
216times. Attendees, reminders, and extended properties are stored in separate tables and reference the
217event’s _ID to link them with the event.</li>
218
219<li>The {@link android.provider.CalendarContract.Instances} table holds the start and end time for
220occurrences of an event. Each row in this table represents a single occurrence. For one-time events
221there is a one-to-one mapping of instances to events. For recurring events, multiple rows are
222automatically generated to correspond to the multiple occurrences of that event.</li>
223
224<li>The {@link android.provider.CalendarContract.Attendees} table holds the event attendee or guest
225information. Each row represents a single guest of an event. It specifies the type of guest the
226person is and the person’s attendance response for the event.</li>
227
228<li>The {@link android.provider.CalendarContract.Reminders} table holds the alert/notification data.
229Each row represents a single alert for an event. An event can have multiple reminders. The number of
230reminders per event is specified in MAX_REMINDERS, which is set by the Sync Adapter that owns the
231given calendar. Reminders are specified in minutes before the event and have a type.</li>
232
233<li>The {@link android.provider.CalendarContract.ExtendedProperties} table hold opaque data fields
234used
235by the sync adapter. The provider takes no action with items in this table except to delete them
236when their related events are deleted.</li>
237</ul>
238
239<p>To access a user’s calendar data with the calendar provider, your application must request
240permission from the user by declaring <uses-permission
241android:name="android.permission.READ_CALENDAR" /> (for read access) and <uses-permission
242android:name="android.permission.WRITE_CALENDAR" /> (for write access) in their manifest files.</p>
243
244<p>However, if all you want to do is add an event to the user’s calendar, you can instead use an
245INSERT
246{@link android.content.Intent} to start an activity in the Calendar app that creates new events.
247Using the intent does not require the WRITE_CALENDAR permission and you can specify the {@link
248android.provider.CalendarContract#EXTRA_EVENT_BEGIN_TIME} and {@link
249android.provider.CalendarContract#EXTRA_EVENT_END_TIME} extra fields to pre-populate the form with
250the time of the event. The values for these times must be in milliseconds from the epoch. You must
251also specify {@code “vnd.android.cursor.item/event”} as the intent type.</p>
252
253
254
255
256
257<h3 id="Camera">Camera</h3>
258
259<p>The {@link android.hardware.Camera} APIs now support face detection and control for metering and
260focus areas.</p>
261
262<h4>Face Detection</h4>
263
264<p>Camera apps can now enhance their abilities with Android’s face detection software, which not
265only
266detects the face of a subject, but also specific facial features, such as the eyes and mouth. </p>
267
268<p>To detect faces in your camera application, you must register a {@link
269android.hardware.Camera.FaceDetectionListener} by calling {@link
270android.hardware.Camera#setFaceDetectionListener setFaceDetectionListener()}. You can then start
271your camera surface and start detecting faces by calling {@link
272android.hardware.Camera#startFaceDetection}.</p>
273
274<p>When the system detects a face, it calls the {@link
275android.hardware.Camera.FaceDetectionListener#onFaceDetection onFaceDetection()} callback in your
276implementation of {@link android.hardware.Camera.FaceDetectionListener}, including an array of
277{@link android.hardware.Camera.Face} objects.</p>
278
279<p>An instance of the {@link android.hardware.Camera.Face} class provides various information about
280the
281face detected by the camera, including:</p>
282<ul>
283<li>A {@link android.graphics.Rect} that specifies the bounds of the face, relative to the camera's
284current field of view</li>
285<li>An integer betwen 0 and 100 that indicates how confident the system is that the object is a
286human
287face</li>
288<li>A unique ID so you can track multiple faces</li>
289<li>Several {@link android.graphics.Point} objects that indicate where the eyes and mouth are
290located</li>
291</ul>
292
293
294<h4>Focus and Metering Areas</h4>
295
296<p>Camera apps can now control the areas that the camera uses for focus and when metering white
297balance
298and auto-exposure (when supported by the hardware). Both features use the new {@link
299android.hardware.Camera.Area} class to specify the region of the camera’s current view that should
300be focused or metered. An instance of the {@link android.hardware.Camera.Area} class defines the
301bounds of the area with a {@link android.graphics.Rect} and the weight of the
302area&mdash;representing the level of importance of that area, relative to other areas in
303consideration&mdash;with an integer.</p>
304
305<p>Before setting either a focus area or metering area, you should first call {@link
306android.hardware.Camera.Parameters#getMaxNumFocusAreas} or {@link
307android.hardware.Camera.Parameters#getMaxNumMeteringAreas}, respectively. If these return zero, then
308the device does not support the respective feature. </p>
309
310<p>To specify the focus or metering areas to use, simply call {@link
311android.hardware.Camera.Parameters#setFocusAreas setFocusAreas()} or {@link
312android.hardware.Camera.Parameters#setFocusAreas setMeteringAreas()}. Each take a {@link
313java.util.List} of {@link android.hardware.Camera.Area} objects that indicate the areas to consider
314for focus or metering. For example, you might implement a feature that allows the user to set the
315focus area by touching an area of the preview, which you then translate to an {@link
316android.hardware.Camera.Area} object and set the focus to that spot. The focus or exposure in that
317area will continually update as the scene in the area changes.</p>
318
319
320<h4>Other Camera Features</h4>
321<ul>
322<li>Capture photos during video recording
323While recording video, you can now call {@link android.hardware.Camera#takePicture takePicture()} to
324save a photo without interrupting the video session. Before doing so, you should call {@link
325android.hardware.Camera.Parameters#isVideoSnapshotSupported} to be sure the hardware supports
326it.</li>
327
328<li>Lock auto exposure and white balance with {@link
329android.hardware.Camera.Parameters#setAutoExposureLock setAutoExposureLock()} and {@link
330android.hardware.Camera.Parameters#setAutoWhiteBalanceLock setAutoWhiteBalanceLock()}, to prevent
331these properties from changing.</li>
332</ul>
333
334<h4>Camera Broadcast Intents</h4>
335
336<ul>
337<li>{@link android.hardware.Camera#ACTION_NEW_PICTURE Camera.ACTION_NEW_PICTURE}
338This indicates that the user has captured a new photo. The built-in camera app invokes this
339broadcast after a photo is captured and third-party camera apps should also broadcast this intent
340after capturing a photo.</li>
341<li>{@link android.hardware.Camera#ACTION_NEW_VIDEO Camera.ACTION_NEW_VIDEO}
342This indicates that the user has captured a new video. The built-in camera app invokes this
343broadcast after a video is recorded and third-party camera apps should also broadcast this intent
344after capturing a video.</li>
345</ul>
346
347
348
349
350
351<h3 id="Multimedia">Multimedia</h3>
352
353<p>Android 4.0 adds several new APIs for applications that interact with media such as photos,
354videos,
355and music.</p>
356
357
358<h4>Media Player</h4>
359
360<ul>
361<li>Streaming online media from {@link android.media.MediaPlayer} now requires {@link
362android.Manifest.permission#INTERNET} permission. If you use {@link android.media.MediaPlayer} to
363play content from the internet, be sure to add the {@link android.Manifest.permission#INTERNET}
364permission or else your media playback will not work beginning with Android 4.0.</li>
365<li>{@link android.media.MediaPlayer#setSurface(Surface) setSurface()} allows you define a {@link
366android.view.Surface} to behave as the video sink.</li>
367<li>{@link android.media.MediaPlayer#setDataSource(Context,Uri,Map) setDataSource()} allows you to
368send additional HTTP headers with your request, which can be useful for HTTP(S) live streaming</li>
369<li>HTTP(S) live streaming now respects HTTP cookies across requests</li>
370</ul>
371
372<h4>Media Type Support</h4>
373
374<p>Android 4.0 adds support for:</p>
375<ul>
376<li>HTTP/HTTPS live streaming protocol version 3 </li>
377<li>ADTS raw AAC audio encoding</li>
378<li>WEBP images</li>
379<li>Matroska video</li>
380</ul>
381<p>For more info, see <a href=”{@docRoot}guide/appendix/media-formats.html”>Supported Media
382Formats</a>.</p>
383
384
385<h4>Remote Control Client</h4>
386
387<p>The new {@link android.media.RemoteControlClient} allows media players to enable playback
388controls
389from remote control clients such as the device lock screen. Media players can also expose
390information about the media currently playing for display on the remote control, such as track
391information and album art.</p>
392
393<p>To enable remote control clients for your media player, instantiate a {@link
394android.media.RemoteControlClient} with a {@link android.app.PendingIntent} that broadcasts {@link
395android.content.Intent#ACTION_MEDIA_BUTTON}. The intent must also declare the explicit {@link
396android.content.BroadcastReceiver} component in your app that handles the {@link
397android.content.Intent#ACTION_MEDIA_BUTTON} event.</p>
398
399<p>To declare which media control inputs your player can handle, you must call {@link
400android.media.RemoteControlClient#setTransportControlFlags setTransportControlFlags()} on your
401{@link android.media.RemoteControlClient}, passing a set of {@code FLAG_KEY_MEDIA_*} flags, such as
402{@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_PREVIOUS} and {@link
403android.media.RemoteControlClient#FLAG_KEY_MEDIA_NEXT}.</p>
404
405<p>You must then register your {@link android.media.RemoteControlClient} by passing it to {@link
406android.media.AudioManager#registerRemoteControlClient MediaManager.registerRemoteControlClient()}.
407Once registered, the broadcast receiver you declared when you instantiated the {@link
408android.media.RemoteControlClient} will receive {@link android.content.Intent#ACTION_MEDIA_BUTTON}
409events when a button is pressed from a remote control. The intent you receive includes the {@link
410android.view.KeyEvent} for the media key pressed, which you can retrieve from the intent with {@link
411android.content.Intent#getParcelableExtra getParcelableExtra(Intent.EXTRA_KEY_EVENT)}.</p>
412
413<p>To display information on the remote control about the media playing, call {@link
414android.media.RemoteControlClient#editMetadata editMetaData()} and add metadata to the returned
415{@link android.media.RemoteControlClient.MetadataEditor}. You can supply a bitmap for media artwork,
416numerical information such as elapsed time, and text information such as the track title. For
417information on available keys see the {@code METADATA_KEY_*} flags in {@link
418android.media.MediaMetadataRetriever}.</p>
419
420<p>For a sample implementation, see the <a
421href=”{@docRoot}resources/samples/RandomMusicPlayer/index.html”>Random Music Player</a>, which
422provides compatibility logic such that it enables the remote control client while continuing to
423support Android 2.1 devices.</p>
424
425
426<h4>Media Effects</h4>
427
428<p>A new media effects framework allows you to apply a variety of visual effects to images and
429videos.
430The system performs all effects processing on the GPU to obtain maximum performance. Applications in
431Android 4.0 such as Google Talk or the Gallery editor make use of the effects API to apply real-time
432effects to video and photos.</p>
433
434<p>For maximum performance, effects are applied directly to OpenGL textures, so your application
435must
436have a valid OpenGL context before it can use the effects APIs. The textures to which you apply
437effects may be from bitmaps, videos or even the camera. However, there are certain restrictions that
438textures must meet:</p>
439<ol>
440<li>They must be bound to a {@link android.opengl.GLES20#GL_TEXTURE_2D} texture image</li>
441<li>They must contain at least one mipmap level</li>
442</ol>
443
444<p>An {@link android.media.effect.Effect} object defines a single media effect that you can apply to
445an
446image frame. The basic workflow to create an {@link android.media.effect.Effect} is:</p>
447
448<ol>
449<li>Call {@link android.media.effect.EffectContext#createWithCurrentGlContext
450EffectContext.createWithCurrentGlContext()} from your OpenGL ES 2.0 context.</li>
451<li>Use the returned {@link android.media.effect.EffectContext} to call {@link
452android.media.effect.EffectContext#getFactory EffectContext.getFactory()}, which returns an instance
453of {@link android.media.effect.EffectFactory}.</li>
454<li>Call {@link android.media.effect.EffectFactory#createEffect createEffect()}, passing it an
455effect
456name from @link android.media.effect.EffectFactory}, such as {@link
457android.media.effect.EffectFactory#EFFECT_FISHEYE} or {@link
458android.media.effect.EffectFactory#EFFECT_VIGNETTE}.</li>
459</ol>
460
461<p>Not all devices support all effects, so you must first check if the desired effect is supported
462by
463calling {@link android.media.effect.EffectFactory#isEffectSupported isEffectSupported()}.</p>
464
465<p>You can adjust the effect’s parameters by calling {@link android.media.effect.Effect#setParameter
466setParameter()} and passing a parameter name and parameter value. Each type of effect accepts
467different parameters, which are documented with the effect name. For example, {@link
468android.media.effect.EffectFactory#EFFECT_FISHEYE} has one parameter for the {@code scale} of the
469distortion.</p>
470
471<p>To apply an effect on a texture, call {@link android.media.effect.Effect#apply apply()} on the
472{@link
473android.media.effect.Effect} and pass in the input texture, it’s width and height, and the output
474texture. The input texture must be bound to a {@link android.opengl.GLES20#GL_TEXTURE_2D} texture
475image (usually done by calling the {@link android.opengl.GLES20#glTexImage2D glTexImage2D()}
476function). You may provide multiple mipmap levels. If the output texture has not been bound to a
477texture image, it will be automatically bound by the effect as a {@link
478android.opengl.GLES20#GL_TEXTURE_2D}. It will contain one mipmap level (0), which will have the same
479size as the input.</p>
480
481
482
483
484
485
486
487<h3 id="Bluetooth">Bluetooth</h3>
488
489<p>Android now supports Bluetooth Health Profile devices, so you can create applications that use
490Bluetooth to communicate with health devices that support Bluetooth, such as heart-rate monitors,
491blood meters, thermometers, and scales.</p>
492
493<p>Similar to regular headset and A2DP profile devices, you must call {@link
494android.bluetooth.BluetoothAdapter#getProfileProxy getProfileProxy()} with a {@link
495android.bluetooth.BluetoothProfile.ServiceListener} and the {@link
496android.bluetooth.BluetoothProfile#HEALTH} profile type to establish a connection with the profile
497proxy object.</p>
498
499<p>Once you’ve acquired the Health profile proxy (the {@link android.bluetooth.BluetoothHealth}
500object), connecting to and communicating with paired health devices involves the following new
501Bluetooth classes:</p>
502<ul>
503<li>{@link android.bluetooth.BluetoothHealthCallback}: You must extend this class and implement the
504callback methods to receive updates about changes in the application’s registration state and
505Bluetooth channel state.</li>
506<li>{@link android.bluetooth.BluetoothHealthAppConfiguration}: During callbacks to your {@link
507android.bluetooth.BluetoothHealthCallback}, you’ll receive an instance of this object, which
508provides configuration information about the available Bluetooth health device, which you must use
509to perform various operations such as initiate and terminate connections with the {@link
510android.bluetooth.BluetoothHealth} APIs.</li>
511</ul>
512
513<p>For more information about using the Bluetooth Health profile, see the documentation for {@link
514android.bluetooth.BluetoothHealth}.</p>
515
516
517<h3 id="AndroidBeam">Android Beam (NDEF Push with NFC)</h3>
518
519<p>Android Beam allows you to send NDEF messages (an NFC standard for data stored on NFC tags) from
520one
521device to another (a process also known as “NDEF Push”). The data transfer is initiated when two
522Android-powered devices that support Android Beam are in close proximity (about 4 cm), usually with
523their backs touching. The data inside the NDEF message can contain any data that you wish to share
524between devices. For example, the People app shares contacts, YouTube shares videos, and Browser
525shares URLs using Android Beam.</p>
526
527<p>To transmit data between devices using Android Beam, you need to create an {@link
528android.nfc.NdefMessage} that contains the information you want to share while your activity is in
529the foreground. You must then pass the
530{@link android.nfc.NdefMessage} to the system in one of two ways:</p>
531
532<ul>
533<li>Define a single {@link android.nfc.NdefMessage} to use from the activity:
534<p>Call {@link android.nfc.NfcAdapter#setNdefPushMessage setNdefPushMessage()} at any time to set
535the
536message you want to send. For instance, you might call this method and pass it your {@link
537android.nfc.NdefMessage} during your activity’s {@link android.app.Activity#onCreate onCreate()}
538method. Then, whenever Android Beam is activated with another device while your activity is in the
539foreground, the system sends that {@link android.nfc.NdefMessage} to the other device.</p></li>
540
541<li>Define the {@link android.nfc.NdefMessage} depending on the current context:
542<p>Implement {@link android.nfc.NfcAdapter.CreateNdefMessageCallback}, in which the {@link
543android.nfc.NfcAdapter.CreateNdefMessageCallback#createNdefMessage createNdefMessage()} callback
544method returns the {@link android.nfc.NdefMessage} you want to send. Then pass the {@link
545android.nfc.NfcAdapter.CreateNdefMessageCallback} to {@link
546android.nfc.NfcAdapter#setNdefPushMessageCallback setNdefPushMessageCallback()}. In this case, when
547Android Beam is activated with another device while your activity is in the foreground, the system
548calls {@link android.nfc.NfcAdapter.CreateNdefMessageCallback#createNdefMessage createNdefMessage()}
549to retrieve the {@link android.nfc.NdefMessage} you want to send. This allows you to create a
550different {@link android.nfc.NdefMessage} for each occurrence, depending on the user context (such
551as which contact in the People app is currently visible).</p></li>
552</ul>
553
554<p>In case you want to run some specific code once the system has successfully delivered your NDEF
555message to the other device, you can implement {@link
556android.nfc.NfcAdapter.OnNdefPushCompleteCallback} and set it with {@link
557android.nfc.NfcAdapter#setOnNdefPushCompleteCallback setNdefPushCompleteCallback()}. The system will
558then call {@link android.nfc.NfcAdapter.OnNdefPushCompleteCallback#onNdefPushComplete
559onNdefPushComplete()} when the message is delivered.</p>
560
561<p>On the receiving device, the system dispatches NDEF Push messages in a similar way to regular NFC
562tags. The system invokes an intent with the {@link android.nfc.NfcAdapter#ACTION_NDEF_DISCOVERED}
563action to start an activity, with either a URL or a MIME type set according to the first {@link
564android.nfc.NdefRecord} in the {@link android.nfc.NdefMessage}. For the activity you want to
565respond, you can set intent filters for the URLs or MIME types your app cares about. For more
566information about Tag Dispatch see the <a
567href=”{@docRoot}guide/topics/nfc/index.html#dispatch”>NFC</a> developer guide.</p>
568
569<p>If you want your {@link android.nfc.NdefMessage} to carry a URI, you can now use the convenience
570method {@link android.nfc.NdefRecord#createUri createUri} to construct a new {@link
571android.nfc.NdefRecord} based on either a string or a {@link android.net.Uri} object. If the URI is
572a special format that you want your application to also receive during an Android Beam event, you
573should create an intent filter for your activity using the same URI scheme in order to receive the
574incoming NDEF message.</p>
575
576<p>You may also want to pass an “Android application record” with your {@link
577android.nfc.NdefMessage}
578in order to guarantee a specific application handles an NDEF message, regardless of whether other
579applications filter for the same intent. You can create an Android application record by calling
580{@link android.nfc.NdefRecord#createApplicationRecord createApplicationRecord()}, passing it the
581application’s package name. When the other device receives the NDEF message with this record, the
582system automatically starts the application matching the package name. If the target device does not
583currently have the application installed, the system uses the Android application record to launch
584Android Market and take the user to the application to install it.</p>
585
586<p>If your application doesn’t use NFC APIs to perform NDEF Push messaging, then Android provides a
587default behavior: When your application is in the foreground on one device and Android Beam is
588invoked with another Android-powered device, then the other device receives an NDEF message with an
589Android application record that identifies your application. If the receiving device has the
590application installed, the system launches it; if it’s not installed, Android Market opens and takes
591the user to your application so they can install it.</p>
592
593
594
595
596
597<h3 id="P2pWiFi">Peer-to-peer Wi-Fi</h3>
598
599<p>Android now supports Wi-Fi Direct&trade; for peer-to-peer (P2P) connections between
600Android-powered
601devices and other device types without a hotspot or Internet connection. The Android framework
602provides a set of Wi-Fi P2P APIs that allow you to discover and connect to other devices when each
603device supports Wi-Fi Direct&trade;, then communicate over a speedy connection across distances much
604longer than a Bluetooth connection.</p>
605
606<p>A new package, {@link android.net.wifi.p2p}, contains all the APIs for performing peer-to-peer
607connections with Wi-Fi. The primary class you need to work with is {@link
608android.net.wifi.p2p.WifiP2pManager}, for which you can get an instance by calling {@link
609android.app.Activity#getSystemService getSystemService(WIFI_P2P_SERVICE)}. The {@link
610android.net.wifi.p2p.WifiP2pManager} provides methods that allow you to:</p>
611<ul>
612<li>Initialize your application for P2P connections by calling {@link
613android.net.wifi.p2p.WifiP2pManager#initialize initialize()}</li>
614<li>Discover nearby devices by calling {@link android.net.wifi.p2p.WifiP2pManager#discoverPeers
615discoverPeers()}</li>
616<li>Start a P2P connection by calling {@link android.net.wifi.p2p.WifiP2pManager#connect
617connect()}</li>
618<li>And more</li>
619</ul>
620
621<p>Several other interfaces and classes are necessary as well, such as:</p>
622<ul>
623<li>The {@link android.net.wifi.p2p.WifiP2pManager.ActionListener} interface allows you to receive
624callbacks when an operation such as discovering peers or connecting to them succeeds or fails.</li>
625<li>{@link android.net.wifi.p2p.WifiP2pManager.PeerListListener} interface allows you to receive
626information about discovered peers. The callback provides a {@link
627android.net.wifi.p2p.WifiP2pDeviceList}, from which you can retrieve a {@link
628android.net.wifi.p2p.WifiP2pDevice} object for each device within range and get information such as
629the device name, address, device type, the WPS configurations the device supports, and more.</li>
630<li>The {@link android.net.wifi.p2p.WifiP2pManager.GroupInfoListener} interface allows you to
631receive
632information about a P2P group. The callback provides a {@link android.net.wifi.p2p.WifiP2pGroup}
633object, which provides group information such as the owner, the network name, and passphrase.</li>
634<li>{@link android.net.wifi.p2p.WifiP2pManager.ConnectionInfoListener} interface allows you to
635receive
636information about the current connection. The callback provides a {@link
637android.net.wifi.p2p.WifiP2pInfo} object, which has information such as whether a group has been
638formed and who is the group owner.</li>
639</ul>
640
641<p>In order to use the Wi-Fi P2P APIs, your app must request the following user permissions:</p>
642<ul>
643<li>{@link android.Manifest.permission#ACCESS_WIFI_STATE}</li>
644<li>{@link android.Manifest.permission#CHANGE_WIFI_STATE}</li>
645<li>{@link android.Manifest.permission#INTERNET} (even though your app doesn’t technically connect
646to
647the Internet, the WiFi Direct implementation uses traditional sockets that do require Internet
648permission to work).</li>
649</ul>
650
651<p>The Android system also broadcasts several different actions during certain Wi-Fi P2P events:</p>
652<ul>
653<li>{@link android.net.wifi.p2p.WifiP2pManager#WIFI_P2P_CONNECTION_CHANGED_ACTION}: The P2P
654connection
655state has changed. This carries {@link android.net.wifi.p2p.WifiP2pManager#EXTRA_WIFI_P2P_INFO} with
656a {@link android.net.wifi.p2p.WifiP2pInfo} object and {@link
657android.net.wifi.p2p.WifiP2pManager#EXTRA_NETWORK_INFO} with a {@link android.net.NetworkInfo}
658object.</li>
659<li>{@link android.net.wifi.p2p.WifiP2pManager#WIFI_P2P_STATE_CHANGED_ACTION}: The P2P state has
660changed
661between enabled and disabled. It carries {@link
662android.net.wifi.p2p.WifiP2pManager#EXTRA_WIFI_STATE} with either {@link
663android.net.wifi.p2p.WifiP2pManager#WIFI_P2P_STATE_DISABLED} or {@link
664android.net.wifi.p2p.WifiP2pManager#WIFI_P2P_STATE_ENABLED}</li>
665<li>{@link android.net.wifi.p2p.WifiP2pManager#WIFI_P2P_PEERS_CHANGED_ACTION}: The list of peer
666devices
667has changed.</li>
668<li>{@link android.net.wifi.p2p.WifiP2pManager#WIFI_P2P_THIS_DEVICE_CHANGED_ACTION}: The details for
669this device have changed.</li>
670</ul>
671
672<p>See the {@link android.net.wifi.p2p.WifiP2pManager} documentation for more information. Also
673look
674at the <a href=”{@docRoot}resources/samples/WiFiDirectDemo/index.html”>Wi-Fi Direct</a> sample
675application for example code.</p>
676
677
678
679
680
681<h3 id="NetworkData">Network Data</h3>
682
683<p>Android 4.0 gives users precise visibility of how much network data applications are using. The
684Settings app provides controls that allow users to manage set limits for network data usage and even
685disable the use of background data for individual apps. In order to avoid users disabling your app’s
686access to data from the background, you should develop strategies to use use the data connection
687efficiently and vary your usage depending on the type of connection available.</p>
688
689<p>If your application performs a lot of network transactions, you should provide user settings that
690allow users to control your app’s data habits, such as how often your app syncs data, whether to
691perform uploads/downloads only when on Wi-Fi, whether to use data while roaming, etc. With these
692controls available to them, users are much less likely to disable your app’s access to data when
693they approach their limits, because they can instead precisely control how much data your app uses.
694When you provide an activity with these settings, you should include in its manifest declaration an
695intent filter for the {@link android.content.Intent#ACTION_MANAGE_NETWORK_USAGE} action. For
696example:</p>
697
698<pre>
699&lt;activity android:name="DataPreferences" android:label="@string/title_preferences">
700 &lt;intent-filter>
701 &lt;action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
702 &lt;category android:name="android.intent.category.DEFAULT" />
703 &lt;/intent-filter>
704&lt;/activity>
705</pre>
706
707<p>This intent filter indicates to the system that this is the application that controls your
708application’s data usage. Thus, when the user inspects how much data your app is using from the
709Settings app, a “View application settings” button is available that launches your activity so the
710user can refine how much data your app uses.</p>
711
712<p>Also beware that {@link android.net.ConnectivityManager#getBackgroundDataSetting()} is now
713deprecated and always returns true&mdash;use {@link
714android.net.ConnectivityManager#getActiveNetworkInfo()} instead. Before you attempt any network
715transactions, you should always call {@link android.net.ConnectivityManager#getActiveNetworkInfo()}
716to get the {@link android.net.NetworkInfo} that represents the current network and query {@link
717android.net.NetworkInfo#isConnected()} to check whether the device has a
718connection. You can then check various other connection properties, such as whether the device is
719roaming or connected to Wi-Fi.</p>
720
721
722
723
724
725
726
727<h3 id="Sensors">Device Sensors</h3>
728
729<p>Two new sensor types have been added in Android 4.0: {@link
730android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE} and {@link
731android.hardware.Sensor#TYPE_RELATIVE_HUMIDITY}. </p>
732
733<p>{@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE} is a temperature sensor that provides
734the ambient (room) temperature near a device. This sensor reports data in degrees Celsius. {@link
735android.hardware.Sensor#TYPE_RELATIVE_HUMIDITY} is a humidity sensor that provides the relative
736ambient (room) humidity. The sensor reports data as a percentage. If a device has both {@link
737android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE} and {@link
738android.hardware.Sensor#TYPE_RELATIVE_HUMIDITY} sensors, you can use them to calculate the dew point
739and the absolute humidity.</p>
740
741<p>The existing temperature sensor ({@link android.hardware.Sensor#TYPE_TEMPERATURE}) has been
742deprecated. You should use the {@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE} sensor
743instead.</p>
744
745<p>Additionally, Android’s three synthetic sensors have been improved so they now have lower latency
746and smoother output. These sensors include the gravity sensor ({@link
747android.hardware.Sensor#TYPE_GRAVITY}), rotation vector sensor ({@link
748android.hardware.Sensor#TYPE_ROTATION_VECTOR}), and linear acceleration sensor ({@link
749android.hardware.Sensor#TYPE_LINEAR_ACCELERATION}). The improved sensors rely on the gyroscope
750sensor to improve their output so the sensors appear only on devices that have a gyroscope. If a
751device already provides one of the sensors, then that sensor appears as a second sensor on the
752device. The three improved sensors have a version number of 2.</p>
753
754
755
756
757
758
759
760
761<h3 id="Renderscript">Renderscript</h3>
762
763<p>Three major features have been added to Renderscript:</p>
764
765<ul>
766 <li>Off-screen rendering to a framebuffer object</li>
767 <li>Rendering inside a view</li>
768 <li>RS for each from the framework APIs</li>
769</ul>
770
771<p>The {@link android.renderscript.Allocation} class now supports a {@link
772android.renderscript.Allocation#USAGE_GRAPHICS_RENDER_TARGET} memory space, which allows you to
773render things directly into the {@link android.renderscript.Allocation} and use it as a framebuffer
774object. </p>
775
776<p>{@link android.renderscript.RSTextureView} provides a means to display Renderscript graphics
777inside
778of a normal View, unlike {@link android.renderscript.RSSurfaceView}, which creates a separate
779window. This key difference allows you to do things such as move, transform, or animate an {@link
780android.renderscript.RSTextureView} as well as draw Renderscript graphics inside the View alongside
781other traditional View widgets.</p>
782
783<p>The {@link android.renderscript.Script#forEach forEach()} method allows you to call Renderscript
784compute scripts from the VM level and have them automatically delegated to available cores on the
785device. You do not use this method directly, but any compute Renderscript that you write will have a
786{@link android.renderscript.Script#forEach forEach()} method that you can call in the reflected
787Renderscript class. You can call the reflected {@link android.renderscript.Script#forEach forEach()}
788method by passing in an input {@link android.renderscript.Allocation} to process, an output {@link
789android.renderscript.Allocation} to write the result to, and a data structure if the Renderscript
790needs more information in addition to the {@link android.renderscript.Allocation}s to. Only one of
791the {@link android.renderscript.Allocation}s is necessary and the data structure is optional.</p>
792
793
794
795
796
797
798<h3 id="A11y">Accessibility</h3>
799
800<p>Android 4.0 improves accessibility for users with disabilities with the Touch Exploration service
801and provides extended APIs for developers of new accessibility services.</p>
802
803<h4>Touch Exploration</h4>
804
805<p>Users with vision loss can now explore applications by touching areas of the screen and hearing
806voice descriptions of the content. The “Explore by Touch” feature works like a virtual cursor as the
807user drags a finger across the screen.</p>
808
809<p>You don’t have to use any new APIs to enhance touch exploration in your application, because the
810existing {@link android.R.attr#contentDescription android:contentDescription}
811attribute and {@link android.view.View#setContentDescription setContentDescription()} method is all
812you need. Because touch exploration works like a virtual cursor, it allows screen readers to
813identify the descriptive the same way that screen readers can when navigating with a d-pad or
814trackball. So this is a reminder to provide descriptive text for the views in your application,
815especially for {@link android.widget.ImageButton}, {@link android.widget.EditText}, {@link
816android.widget.CheckBox} and other interactive widgets that might not contain text information by
817default.</p>
818
819<h4>Accessibility for Custom Views</h4>
820
821<p>Developers of custom Views, ViewGroups and widgets can make their components compatible with
822accessibility services like Touch Exploration. For custom views and widgets targeted for Android 4.0
823and later, developers should implement the following accessibility API methods in their classes:</p>
824<ul>
825<li>These two methods initiate the accessibility event generation process and must be implemented by
826your custom view class.
827 <ul>
828 <li>{@link android.view.View#sendAccessibilityEvent(int) sendAccessibilityEvent()} If
829accessibility
830 is
831 not enabled, this call has no effect.</li>
832 <li>{@link
833 android.view.View#sendAccessibilityEventUnchecked(android.view.accessibility.AccessibilityEvent)
834 sendAccessibilityEventUnchecked()} - This method executes regardless of whether accessibility is
835 enabled or not.</li>
836 </ul>
837</li>
838
839<li>These methods are called in order by the sendAccessibilityEvent methods listed above to collect
840accessibility information about the view, and its child views.
841 <ul>
842 <li>{@link
843 android.view.View#onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent)
844 onInitializeAccessibilityEvent()} - This method collects information about the view. If your
845 application has specific requirements for accessibility, you should extend this method to add that
846 information to the {@link android.view.accessibility.AccessibilityEvent}.</li>
847
848 <li>{@link
849
850android.view.View#dispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent)
851 dispatchPopulateAccessibilityEvent()} is called by the framework to request text information for
852 this view and its children. This method calls {@link
853 android.view.View#onPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent)
854 onPopulateAccessibilityEvent()} first on the current view and then on its children.</li>
855 </ul>
856</li>
857
858<li>The {@link
859android.view.View#onInitializeAccessibilityNodeInfo onInitializeAccessibilityNodeInfo()} method
860provides additional context information for
861accessibility services. You should implement or override this method to provide improved information
862for accessibility services investigating your custom view.</li>
863
864<li>Custom {@link android.view.ViewGroup} classes should also implement {@link
865android.view.ViewGroup#onRequestSendAccessibilityEvent(android.view.View,
866android.view.accessibility.AccessibilityEvent) onRequestSendAccessibilityEvent()} </li>
867</ul>
868
869<p>Developers who want to maintain compatibility with Android versions prior to 4.0, while still
870providing support for new the accessibility APIs, can use the {@link
871android.view.View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)
872setAccessibilityDelegate()} method to provide an {@link android.view.View.AccessibilityDelegate}
873containing implementations of the new accessibility API methods while maintaining compatibility with
874prior releases.</p>
875
876
877
878<h4>Accessibility Service APIs</h4>
879
880<p>Accessibility events have been significantly improved to provide better information for
881accessibility services. In particular, events are generated based on view composition, providing
882better context information and allowing accessibility service developers to traverse view
883hierarchies to get additional view information and deal with special cases.</p>
884
885<p>To access additional content information and traverse view hierarchies, accessibility service
886application developers should use the following procedure.</p>
887<ol>
888<li>Upon receiving an {@link android.view.accessibility.AccessibilityEvent} from an application,
889call
890the {@link android.view.accessibility.AccessibilityEvent#getRecord(int)
891AccessibilityEvent.getRecord()} to retrieve new accessibility information about the state of the
892view.</li>
893<li>From the {@link android.view.accessibility.AccessibilityRecord}, call {@link
894android.view.accessibility.AccessibilityRecord#getSource() getSource()} to retrieve a {@link
895android.view.accessibility.AccessibilityNodeInfo} object.</li>
896<li>With the {@link android.view.accessibility.AccessibilityNodeInfo}, call {@link
897android.view.accessibility.AccessibilityNodeInfo#getParent getParent()} or {@link
898android.view.accessibility.AccessibilityNodeInfo#getChild getChild()} to traverse the view
899hierarchy and get additional context information.</li>
900</ol>
901
902<p>In order to retrieve {@link android.view.accessibility.AccessibilityNodeInfo} information, your
903application must request permission to retrieve application window content through a manifest
904declaration that includes a new, separate xml configuration file, which supercedes {@link
905android.accessibilityservice.AccessibilityServiceInfo}. For more information, see {@link
906android.accessibilityservice.AccessibilityService} and {@link
907android.accessibilityservice.AccessibilityService#SERVICE_META_DATA
908AccessibilityService.SERVICE_META_DATA}.</p>
909
910
911
912
913
914
915<h3 id="Enterprise">Enterprise</h3>
916
917<p>Android 4.0 expands the capabilities for enterprise application with the following features.</p>
918
919<h4>VPN Services</h4>
920
921<p>The new {@link android.net.VpnService} allows applications to build their own VPN (Virtual
922Private
923Network), running as a {@link android.app.Service}. A VPN service creates an interface for a virtual
924network with its own address and routing rules and performs all reading and writing with a file
925descriptor.</p>
926
927<p>To create a VPN service, use {@link android.net.VpnService.Builder}, which allows you to specify
928the network address, DNS server, network route, and more. When complete, you can establish the
929interface by calling {@link android.net.VpnService.Builder#establish()}, which returns a {@link
930android.os.ParcelFileDescriptor}. </p>
931
932<p>Because a VPN service can intercept packets, there are security implications. As such, if you
933implement {@link android.net.VpnService}, then your service must require the {@link
934android.Manifest.permission#BIND_VPN_SERVICE} to ensure that only the system can bind to it (only
935the system is granted this permission&mdash;apps cannot request it). To then use your VPN service,
936users must manually enable it in the system settings.</p>
937
938
939<h4>Device Restrictions</h4>
940
941<p>Applications that manage the device restrictions can now disable the camera using {@link
942android.app.admin.DevicePolicyManager#setCameraDisabled setCameraDisabled()} and the {@link
943android.app.admin.DeviceAdminInfo#USES_POLICY_DISABLE_CAMERA} property (applied with a {@code
944&lt;disable-camera /&gt;} element in the policy configuration file).</p>
945
946
947<h4>Certificate Management</h4>
948
949<p>The new {@link android.security.KeyChain} class provides APIs that allow you to import and access
950certificates and key stores in credential storage. See the {@link android.security.KeyChain}
951documentation for more information.</p>
952
953
954
955
956<h3 id="Voicemail">Voicemail</h3>
957
958<p>A new voicemail APIs allows applications to add voicemails to the system. Because the APIs
959currently
960do not allow third party apps to read all the voicemails from the system, the only third-party apps
961that should use the voicemail APIs are those that have voicemail to deliver to the user. For
962instance, it’s possible that a users have multiple voicemail sources, such as one provided by their
963phone’s service provider and others from VoIP or other alternative services. These kinds of apps can
964use the APIs to add voicemail to the system. The built-in Phone application can then present all
965voicemails to the user with a single list. Although the system’s Phone application is the only
966application that can read all the voicemails, each application that provides voicemails can read
967those that it has added to the system.</p>
968
969<p>The {@link android.provider.VoicemailContract} class defines the content provider for the
970voicemail
971APIs. The subclasses {@link android.provider.VoicemailContract.Voicemails} and {@link
972android.provider.VoicemailContract.Status} provide tables in which the voicemail providers can
973insert voicemail data for storage on the device. For an example of a voicemail provider app, see the
974<a href=”{@docRoot}resources/samples/VoicemailProviderDemo/index.html”>Voicemail Provider
975Demo</a>.</p>
976
977
978
979
980<h3 id="SpellChecker">Spell Checker Services</h3>
981
982<p>The new spell checker framework allows apps to create spell checkers in a manner similar to the
983input method framework. To create a new spell checker, you must override the {@link
984android.service.textservice.SpellCheckerService.Session} class to provide spelling suggestions based
985on text provided by the interface callback methods, returning suggestions as a {@link
986android.view.textservice.SuggestionsInfo} object. </p>
987
988<p>Applications with a spell checker service must declare the {@link
989android.Manifest.permission#BIND_TEXT_SERVICE} permission as required by the service, such that
990other services must have this permission in order for them to bind with the spell checker service.
991The service must also declare an intent filter with <action
992android:name="android.service.textservice.SpellCheckerService" /> as the intent’s action and should
993include a {@code &lt;meta-data&gt;} element that declares configuration information for the spell
994checker. </p>
995
996
997
998
999
1000<h3 id="TTS">Text-to-speech Engines</h3>
1001
1002<p>Android’s text-to-speech (TTS) APIs have been greatly extended to allow applications to more
1003easily
1004implement custom TTS engines, while applications that want to use a TTS engine have a couple new
1005APIs for selecting the engine.</p>
1006
1007
1008<h4>Using text-to-speech engines</h4>
1009
1010<p>In previous versions of Android, you could use the {@link android.speech.tts.TextToSpeech} class
1011to
1012perform text-to-speech (TTS) operations using the TTS engine provided by the system or set a custom
1013engine using {@link android.speech.tts.TextToSpeech#setEngineByPackageName
1014setEngineByPackageName()}.
1015In Android 4.0, the {@link android.speech.tts.TextToSpeech#setEngineByPackageName
1016setEngineByPackageName()} method has been deprecated and you can now specify the engine to use with
1017a new {@link android.speech.tts.TextToSpeech} that accepts the package name of a TTS engine.</p>
1018
1019<p>You can also query the available TTS engines with {@link
1020android.speech.tts.TextToSpeech#getEngines()}. This method returns a list of {@link
1021android.speech.tts.TextToSpeech.EngineInfo} objects, which include meta data such as the engine’s
1022icon, label, and package name.</p>
1023
1024
1025<h4>Building text-to-speech engines</h4>
1026
1027<p>Previously, custom engines required that the engine be built using native code, based on a TTS
1028engine header file. In Android 4.0, there is a framework API for building TTS engines. </p>
1029
1030<p>The basic setup requires an implementation of {@link android.speech.tts.TextToSpeechService} that
1031responds to the {@link android.speech.tts.TextToSpeech.Engine#INTENT_ACTION_TTS_SERVICE} intent. The
1032primary work for a TTS engine happens during the {@link
1033android.speech.tts.TextToSpeechService#onSynthesizeText onSynthesizeText()} callback in the {@link
1034android.speech.tts.TextToSpeechService}. The system delivers this method two objects:</p>
1035<ul>
1036<li>{@link android.speech.tts.SynthesisRequest}: This contains various data including the text to
1037synthesize, the locale, the speech rate, and voice pitch.</li>
1038<li>{@link android.speech.tts.SynthesisCallback}: This is the interface by which your TTS engine
1039delivers the resulting speech data as streaming audio, by calling {@link
1040android.speech.tts.SynthesisCallback#start start()} to indicate that the engine is ready to deliver
1041the
1042audio, then call {@link android.speech.tts.SynthesisCallback#audioAvailable audioAvailable()},
1043passing it the audio
1044data in a byte buffer. Once your engine has passed all audio through the buffer, call {@link
1045android.speech.tts.SynthesisCallback#done()}.</li>
1046</ul>
1047
1048<p>Now that the framework supports a true API for creating TTS engines, support for the previous
1049technique using native code has been removed. Watch for a blog post about the compatibility layer
1050that you can use to convert TTS engines built using the previous technique to the new framework.</p>
1051
1052<p>For an example TTS engine using the new APIs, see the <a
1053href=”{@docRoot}resources/samples/TtsEngine/index.html”>Text To Speech Engine</a> sample app.</p>
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065<h3 id="ActionBar">Action Bar</h3>
1066
1067<p>The {@link android.app.ActionBar} has been updated to support several new behaviors. Most
1068importantly, the system gracefully manages the action bar’s size and configuration when running on
1069smaller screens in order to provide an optimal user experience. For example, when the screen is
1070narrow (such as when a handset is in portrait orientation), the action bar’s navigation tabs appear
1071in a “stacked bar,” which appears directly below the main action bar. You can also opt-in to a
1072“split action bar,” which will place all action items in a separate bar at the bottom of the screen
1073when the screen is narrow.</p>
1074
1075
1076<h4>Split Action Bar</h4>
1077
1078<p>If your action bar includes several action items, not all of them will fit into the action bar
1079when on a narrow screen, so the system will place them into the overflow menu. However, Android 4.0
1080allows you to enable “split action bar” so that more action items can appear on the screen in a
1081separate bar at the bottom of the screen. To enable split action bar, add {@link
1082android.R.attr#uiOptions android:uiOptions} with {@code ”splitActionBarWhenNarrow”} to either your
1083{@code &lt;application&gt;} tag or individual {@code &lt;activity&gt;} tags in your manifest file.
1084When enabled, the system will enable the additional bar for action items when the screen is narrow
1085and add all action items to the new bar (no action items will appear in the primary action bar).</p>
1086
1087<p>If you want to use the navigation tabs provided by the {@link android.app.ActionBar.Tab} APIs,
1088but
1089don’t want the stacked bar&mdash;you want only the tabs to appear, then enable the split action bar
1090as described above and also call {@link android.app.ActionBar#setDisplayShowHomeEnabled
1091setDisplayShowHomeEnabled(false)} to disable the application icon in the action bar. With nothing
1092left in the main action bar, it disappears&mdash;all that’s left are the navigation tabs at the top
1093and the action items at the bottom of the screen.</p>
1094
1095
1096<h4>Action Bar Styles</h4>
1097
1098<p>If you want to apply custom styling to the action bar, you can use new style properties {@link
1099android.R.attr#backgroundStacked} and {@link android.R.attr#backgroundSplit} to apply a background
1100drawable or color to the stacked bar and split bar, respectively. You can also set these styles at
1101runtime with {@link android.app.ActionBar#setStackedBackgroundDrawable
1102setStackedBackgroundDrawable()} and {@link android.app.ActionBar#setSplitBackgroundDrawable
1103setSplitBackgroundDrawable()}.</p>
1104
1105
1106<h4>Action Provider</h4>
1107
1108<p>The new {@link android.view.ActionProvider} class facilitates user actions to which several
1109different applications may respond. For example, a “share” action in your application might invoke
1110several different apps that can handle the {@link android.content.Intent#ACTION_SEND} intent and the
1111associated data. In this case, you can use the {@link android.widget.ShareActionProvider} (an
1112extension of {@link android.view.ActionProvider}) in your action bar, instead of a traditional menu
1113item that invokes the intent. The {@link android.widget.ShareActionProvider} populates a drop-down
1114menu with all the available apps that can handle the intent.</p>
1115
1116<p>To declare an action provider for an action item, include the {@code android:actionProviderClass}
1117attribute in the {@code &lt;item&gt;} element for your activity’s options menu, with the class name
1118of the action provider as the attribute value. For example:</p>
1119
1120<pre>
1121&lt;item android:id="@+id/menu_share"
1122 android:title="Share"
1123 android:icon="@drawable/ic_share"
1124 android:showAsAction="ifRoom"
1125 android:actionProviderClass="android.widget.ShareActionProvider" /&gt;
1126</pre>
1127
1128<p>In your activity’s {@link android.app.Activity#onCreateOptionsMenu onCreateOptionsMenu()}
1129callback
1130method, retrieve an instance of the action provider from the menu item and set the intent:</p>
1131
1132<pre>
1133public boolean onCreateOptionsMenu(Menu menu) {
1134 getMenuInflater().inflate(R.menu.options, menu);
1135 ShareActionProvider shareActionProvider =
1136 (ShareActionProvider) menu.findItem(R.id.menu_share).getActionProvider();
1137 // Set the share intent of the share action provider.
1138 shareActionProvider.setShareIntent(createShareIntent());
1139 ...
1140 return super.onCreateOptionsMenu(menu);
1141}
1142</pre>
1143
1144<p>For an example using the {@link android.widget.ShareActionProvider}, see the <a
1145href=”{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/app/ActionBarActionProviderActivity.html”>ActionBarActionProviderActivity</a>
1146class in ApiDemos.</p>
1147
1148
1149<h4>Collapsible Action Views</h4>
1150
1151<p>Menu items that appear as action items can now toggle between their action view state and
1152traditional action item state. Previously only the {@link android.widget.SearchView} supported
1153collapsing when used as an action view, but now you can add an action view for any action item and
1154switch between the expanded state (action view is visible) and collapsed state (action item is
1155visible).</p>
1156
1157<p>To declare that an action item that contains an action view be collapsible, include the {@code
1158“collapseActionView”} flag in the {@code android:showAsAction} attribute for the {@code
1159&lt;item&gt;} element in the menu’s XML file.</p>
1160
1161<p>To receive callbacks when an action view switches between expanded and collapsed, register an
1162instance of {@link android.view.MenuItem.OnActionExpandListener} with the respective {@link
1163android.view.MenuItem} by calling {@link android.view.MenuItem#setOnActionExpandListener
1164setOnActionExpandListener()}. Typically, you should do so during the {@link
1165android.app.Activity#onCreateOptionsMenu onCreateOptionsMenu()} callback.</p>
1166
1167<p>To control a collapsible action view, you can call {@link
1168android.view.MenuItem#collapseActionView()} and {@link android.view.MenuItem#expandActionView()} on
1169the respective {@link android.view.MenuItem}.</p>
1170
1171<p>When creating a custom action view, you can also implement the new {@link
1172android.view.CollapsibleActionView} interface to receive callbacks when the view is expanded and
1173collapsed.</p>
1174
1175
1176<h4>Other APIs for Action Bar</h4>
1177<ul>
1178<li>{@link android.app.ActionBar#setHomeButtonEnabled setHomeButtonEnabled()} allows you to disable
1179the
1180default behavior in which the application icon/logo behaves as a button (pass “false” to disable it
1181as a button).</li>
1182<li>{@link android.app.ActionBar#setIcon setIcon()} and {@link android.app.ActionBar#setLogo
1183setLogo()}
1184to define the action bar icon or logo at runtime.</li>
1185<li>{@link android.app.Fragment#setMenuVisibility Fragment.setMenuVisibility()} allows you to enable
1186or
1187disable the visibility of the options menu items declared by the fragment. This is useful if the
1188fragment has been added to the activity, but is not visible, so the menu items should be
1189hidden.</li>
1190<li>{@link android.app.FragmentManager#invalidateOptionsMenu
1191FragmentManager.invalidateOptionsMenu()}
1192allows you to invalidate the activity options menu during various states of the fragment lifecycle
1193in which using the equivalent method from {@link android.app.Activity} might not be available.</li>
1194</ul>
1195
1196
1197
1198
1199
1200
1201
1202
1203<h3 id="UI">User Interface and Views</h3>
1204
1205<p>Android 4.0 introduces a variety of new views and other UI components.</p>
1206
1207<h4>System UI</h4>
1208
1209<p>Since the early days of Android, the system has managed a UI component known as the <em>status
1210bar</em>, which resides at the top of handset devices to deliver information such as the carrier
1211signal, time, notifications, and so on. Android 3.0 added the <em>system bar</em> for tablet
1212devices, which resides at the bottom of the screen to provide system navigation controls (Home,
1213Back, and so forth) and also an interface for elements traditionally provided by the status bar. In
1214Android 4.0, the system provides a new type of system UI called the <em>navigation bar</em>. The
1215navigation bar shares some qualities with the system bar, because it provides navigation controls
1216for devices that don’t have hardware counterparts for navigating the system, but the navigation
1217controls is all that it provides (a device with the navigation bar, thus, also includes the status
1218bar at the top of the screen).</p>
1219
1220<p>To this day, you can hide the status bar on handsets using the {@link
1221android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN} flag. In Android 4.0, the APIs that control
1222the system bar’s visibility have been updated to better reflect the behavior of both the system bar
1223and navigation bar:</p>
1224<ul>
1225<li>The {@link android.view.View#SYSTEM_UI_FLAG_LOW_PROFILE} flag replaces View.STATUS_BAR_HIDDEN
1226flag
1227(now deprecated). When set, this flag enables “low profile” mode for the system bar or navigation
1228bar. Navigation buttons dim and other elements in the system bar also hide.</li>
1229<li>The {@link android.view.View#SYSTEM_UI_FLAG_VISIBLE} flag replaces the {@code
1230STATUS_BAR_VISIBLE}
1231flag to request the system bar or navigation bar be visible.</li>
1232<li>The {@link android.view.View#SYSTEM_UI_FLAG_HIDE_NAVIGATION} is a new flag that requests that
1233the
1234navigation bar hide completely. Take note that this works only for the <em>navigation bar</em> used
1235by some handsets (it does <strong>not</strong> hide the system bar on tablets). The navigation bar
1236returns as soon as the system receives user input. As such, this mode is generally used for video
1237playback or other cases in which user input is not required.</li>
1238</ul>
1239
1240<p>You can set each of these flags for the system bar by calling {@link
1241android.view.View#setSystemUiVisibility setSystemUiVisibility()} on any view in your activity
1242window. The window manager will combine (OR-together) all flags from all views in your window and
1243apply them to the system UI as long as your window has input focus. When your window loses input
1244focus (the user navigates away from your app, or a dialog appears), your flags cease to have effect.
1245Similarly, if you remove those views from the view hierarchy their flags no longer apply.</p>
1246
1247<p>To synchronize other events in your activity with visibility changes to the system UI (for
1248example,
1249hide the action bar or other UI controls when the system UI hides), you can register a {@link
1250android.view.View.OnSystemUiVisibilityChangeListener} to get a callback when the visibility
1251changes.</p>
1252
1253<p>See the <a
1254href=”{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/OverscanActivity.html”>
1255OverscanActivity</a> class for a demonstration of different system UI options.</p>
1256
1257
1258<h4>GridLayout</h4>
1259
1260<p>{@link android.widget.GridLayout} is a new view group that places child views in a rectangular
1261grid.
1262Unlike {@link android.widget.TableLayout}, {@link android.widget.GridLayout} relies on a flat
1263hierarchy and does not make use of intermediate views such as table rows for providing structure.
1264Instead, children specify which row(s) and column(s) they should occupy (cells can span multiple
1265rows and/or columns), and by default are laid out sequentially across the grid’s rows and columns.
1266The {@link android.widget.GridLayout} orientation determines whether sequential children are by
1267default laid out horizontally or vertically. Space between children may be specified either by using
1268instances of the new {@link android.widget.Space} view or by setting the relevant margin parameters
1269on children.</p>
1270
1271<p>See <a
1272href=”{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/index.html”>ApiDemos</a>
1273for samples using {@link android.widget.GridLayout}.</p>
1274
1275
1276
1277<h4>TextureView</h4>
1278
1279<p>{@link android.view.TextureView} is a new view that allows you to display a content stream, such
1280as
1281a video or an OpenGL scene. Although similar to {@link android.view.SurfaceView}, {@link
1282android.view.TextureView} is unique in that it behaves like a regular view, rather than creating a
1283separate window, so you can treat it like any other {@link android.view.View} object. For example,
1284you can apply transforms, animate it using {@link android.view.ViewPropertyAnimator}, or easily
1285adjust its opacity with {@link android.view.View#setAlpha setAlpha()}.</p>
1286
1287<p>Beware that {@link android.view.TextureView} works only within a hardware accelerated window.</p>
1288
1289<p>For more information, see the {@link android.view.TextureView} documentation.</p>
1290
1291
1292<h4>Switch Widget</h4>
1293
1294<p>The new {@link android.widget.Switch} widget is a two-state toggle that users can drag to one
1295side
1296or the other (or simply tap) to toggle an option between two states.</p>
1297
1298<p>You can declare a switch in your layout with the {@code &lt;Switch&gt;} element. You can use the
1299{@code android:textOn} and {@code android:textOff} attributes to specify the text to appear on the
1300switch when in the on and off setting. The {@code android:text} attribute also allows you to place a
1301label alongside the switch.</p>
1302
1303<p>For a sample using switches, see the <a
1304href=”{@docRoot}resources/samples/ApiDemos/res/layout/switches.html”>switches.xml</a> layout file
1305and respective <a
1306href=”{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/Switches.html”>Switches
1307</a> activity.</p>
1308
1309
1310<h4>Popup Menus</h4>
1311
1312<p>Android 3.0 introduced {@link android.widget.PopupMenu} to create short contextual menus that pop
1313up
1314at an anchor point you specify (usually at the point of the item selected). Android 4.0 extends the
1315{@link android.widget.PopupMenu} with a couple useful features:</p>
1316<ul>
1317<li>You can now easily inflate the contents of a popup menu from an XML <a
1318href=”{@docRoot}guide/topics/resources/menu-resource.html”>menu resource</a> with {@link
1319android.widget.PopupMenu#inflate inflate()}, passing it the menu resource ID.</li>
1320<li>You can also now create a {@link android.widget.PopupMenu.OnDismissListener} that receives a
1321callback when the menu is dismissed.</li>
1322</ul>
1323
1324<h4>Preferences</h4>
1325
1326<p>A new {@link android.preference.TwoStatePreference} abstract class serves as the basis for
1327preferences that provide a two-state selection option. The new {@link
1328android.preference.SwitchPreference} is an extension of {@link
1329android.preference.TwoStatePreference} that provides a {@link android.widget.Switch} widget in the
1330preference view to allow users to toggle a setting on or off without the need to open an additional
1331preference screen or dialog. For example, the Settings application uses a {@link
1332android.preference.SwitchPreference} for the Wi-Fi and Bluetooth settings.</p>
1333
1334
1335<h4>Hover Events</h4>
1336
1337<p>The {@link android.view.View} class now supports “hover” events to enable richer interactions
1338through the use of pointer devices (such as a mouse or other device that drives an on-screen
1339cursor).</p>
1340
1341<p>To receive hover events on a view, implement the {@link android.view.View.OnHoverListener} and
1342register it with {@link android.view.View#setOnHoverListener setOnHoverListener()}. When a hover
1343event occurs on the view, your listener receives a call to {@link
1344android.view.View.OnHoverListener#onHover onHover()}, providing the {@link android.view.View} that
1345received the event and a {@link android.view.MotionEvent} that describes the type of hover event
1346that occurred. The hover event can be one of the following:</p>
1347<ul>
1348<li>{@link android.view.MotionEvent#ACTION_HOVER_ENTER}</li>
1349<li>{@link android.view.MotionEvent#ACTION_HOVER_EXIT}</li>
1350<li>{@link android.view.MotionEvent#ACTION_HOVER_MOVE}</li>
1351</ul>
1352
1353<p>Your {@link android.view.View.OnHoverListener} should return true from {@link
1354android.view.View.OnHoverListener#onHover onHover()} if it handles the hover event. If your
1355listener returns false, then the hover event will be dispatched to the parent view as usual.</p>
1356
1357<p>If your application uses buttons or other widgets that change their appearance based on the
1358current
1359state, you can now use the {@code android:state_hovered} attribute in a <a
1360href=”{@docRoot}guide/topics/resources/drawable-resource.html#StateList”>state list drawable</a> to
1361provide a different background drawable when a cursor hovers over the view.</p>
1362
1363<p>For a demonstration of the new hover events, see the <a
1364href=”{@docRoot}samples/ApiDemos/src/com/example/android/apis/view/Hover.html”>Hover</a> class in
1365ApiDemos.</p>
1366
1367
1368<h4>Stylus and Mouse Button Input Events</h4>
1369
1370<p>Android now provides APIs for receiving input from a stylus input device such as a digitizer
1371tablet
1372peripheral or a stylus-enabled touch screen.</p>
1373
1374<p>Stylus input operates in a similar manner to touch or mouse input. When the stylus is in contact
1375with the digitizer, applications receive touch events just like they would when a finger is used to
1376touch the display. When the stylus is hovering above the digitizer, applications receive hover
1377events just like they would when a mouse pointer was being moved across the display when no buttons
1378are pressed.</p>
1379
1380<p>Your application can distinguish between finger, mouse, stylus and eraser input by querying the
1381“tool type” associated with each pointer in a {@link android.view.MotionEvent} using {@link
1382android.view.MotionEvent#getToolType getToolType()}. The currently defined tool types are: {@link
1383android.view.MotionEvent#TOOL_TYPE_UNKNOWN}, {@link android.view.MotionEvent#TOOL_TYPE_FINGER},
1384{@link android.view.MotionEvent#TOOL_TYPE_MOUSE}, {@link android.view.MotionEvent#TOOL_TYPE_STYLUS},
1385and {@link android.view.MotionEvent#TOOL_TYPE_ERASER}. By querying the tool type, your application
1386can choose to handle stylus input in different ways from finger or mouse input.</p>
1387
1388<p>Your application can also query which mouse or stylus buttons are pressed by querying the “button
1389state” of a {@link android.view.MotionEvent} using {@link android.view.MotionEvent#getButtonState
1390getButtonState()}. The currently defined button states are: {@link
1391android.view.MotionEvent#BUTTON_PRIMARY}, {@link
1392android.view.MotionEvent#BUTTON_SECONDARY}, {@link
1393android.view.MotionEvent#BUTTON_TERTIARY}, {@link android.view.MotionEvent#BUTTON_BACK},
1394and {@link android.view.MotionEvent#BUTTON_FORWARD}.
1395For convenience, the back and forward mouse buttons are automatically mapped to the {@link
1396android.view.KeyEvent#KEYCODE_BACK} and {@link android.view.KeyEvent#KEYCODE_FORWARD} keys. Your
1397application can handle these keys to support mouse button based back and forward navigation.</p>
1398
1399<p>In addition to precisely measuring the position and pressure of a contact, some stylus input
1400devices
1401also report the distance between the stylus tip and the digitizer, the stylus tilt angle, and the
1402stylus orientation angle. Your application can query this information using {@link
1403android.view.MotionEvent#getAxisValue getAxisValue()} with the axis codes {@link
1404android.view.MotionEvent#AXIS_DISTANCE}, {@link android.view.MotionEvent#AXIS_TILT}, and {@link
1405android.view.MotionEvent#AXIS_ORIENTATION}.</p>
1406
1407<p>For a demonstration of tool types, button states and the new axis codes, see the <a
1408href=”{@docRoot}samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html”>TouchPaint
1409</a> class in ApiDemos.</p>
1410
1411
1412
1413
1414
1415
1416<h3 id="Properties">Properties</h3>
1417
1418<p>The new {@link android.util.Property} class provides a fast, efficient, and easy way to specify a
1419property on any object that allows callers to generically set/get values on target objects. It also
1420allows the functionality of passing around field/method references and allows code to set/get values
1421of the property without knowing the details of what the fields/methods are.</p>
1422
1423<p>For example, if you want to set the value of field {@code bar} on object {@code foo}, you would
1424previously do this:</p>
1425<pre>
1426foo.bar = value;
1427</pre>
1428
1429<p>If you want to call the setter for an underlying private field {@code bar}, you would previously
1430do this:</p>
1431<pre>
1432foo.setBar(value);
1433</pre>
1434
1435<p>However, if you want to pass around the {@code foo} instance and have some other code set the
1436{@code bar} value, there is really no way to do it prior to Android 4.0.</p>
1437
1438<p>Using the {@link android.util.Property} class, you can declare a {@link android.util.Property}
1439object {@code BAR} on class {@code Foo} so that you can set the field on instance {@code foo} of
1440class {@code Foo} like this:</p>
1441<pre>
1442BAR.set(foo, value);
1443</pre>
1444
1445<p>The {@link android.view.View} class now leverages the {@link android.util.Property} class to
1446allow you to set various fields, such as transform properties that were added in Android 3.0 ({@link
1447android.view.View#ROTATION}, {@link android.view.View#ROTATION_X}, {@link
1448android.view.View#TRANSLATION_X}, etc.).</p>
1449
1450<p>The {@link android.animation.ObjectAnimator} class also uses the {@link android.util.Property}
1451class, so you can create an {@link android.animation.ObjectAnimator} with a {@link
1452android.util.Property}, which is faster, more efficient, and more type-safe than the string-based
1453approach.</p>
1454
1455
1456
1457
1458
1459
1460<h3 id="HwAccel">Hardware Acceleration</h3>
1461
1462<p>Beginning with Android 4.0, hardware acceleration for all windows is enabled by default if your
1463application has set either <a
1464href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code targetSdkVersion}</a> or
1465<a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a> to
1466{@code “14”} or higher. Hardware acceleration generally results in smoother animations, smoother
1467scrolling, and overall better performance and response to user interaction.</p>
1468
1469<p>If necessary, you can manually disable hardware acceleration with the <a
1470href=”{@docRoot}guide/topics/manifest/activity-element.html#hwaccel”>{@code hardwareAccelerated}</a>
1471attribute for individual <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code
1472&lt;activity&gt;}</a> elements or the <a
1473href="{@docRoot}guide/topics/manifest/application-element.html">{@code &lt;application&gt;}</a>
1474element. You can alternatively disable hardware acceleration for individual views by calling {@link
1475android.view.View#setLayerType setLayerType(LAYER_TYPE_SOFTWARE)}.</p>
1476
1477
1478<h3 id="Jni">JNI Changes</h3>
1479
1480<p>In previous versions of Android, JNI local references weren’t indirect handles; we used direct
1481pointers. This didn’t seem like a problem as long as we didn’t have a garbage collector that moves
1482objects, but it was because it meant that it was possible to write buggy code that still seemed to
1483work. In Android 4.0, we’ve moved to using indirect references so we can detect these bugs before we
1484need third-party native code to be correct.</p>
1485
1486<p>The ins and outs of JNI local references are described in “Local and Global References” in
1487<a href="{@docRoot}guide/practices/design/jni.html">JNI Tips</a>. In Android 4.0, <a
1488href="http://android-developers.blogspot.com/2011/07/debugging-android-jni-with-checkjni.html">CheckJNI</a>
1489has been
1490enhanced to detect these errors. Watch the <a href=”http://android-developers.blogspot.com/”>Android
1491Developers Blog</a> for an upcoming post about common errors with JNI references and how you can fix
1492them.</p>
1493
1494<p>This change in the JNI implementation only affects apps that target Android 4.0 by setting either
1495the <a
1496href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code targetSdkVersion}</a> or
1497<a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a> to
1498{@code “14”} or higher. If you’ve set these attributes to any lower
1499value, then JNI local references will behave the same as in previous versions.</p>
1500
1501
1502
1503
1504
1505<h3 id="WebKit">WebKit</h3>
1506<ul>
1507<li>WebKit updated to version 534.30</li>
1508<li>Support for Indic fonts (Devanagari, Bengali, and Tamil, including the complex character support
1509needed for combining glyphs) in {@link android.webkit.WebView} and the built-in Browser</li>
1510<li>Support for Ethiopic, Georgian, and Armenian fonts in {@link android.webkit.WebView} and the
1511built-in Browser</li>
1512<li>Support for <a
1513href="http://google-opensource.blogspot.com/2009/05/introducing-webdriver.html">WebDriver</a> makes
1514it easier for you to test apps that use {@link android.webkit.WebView}</li>
1515</ul>
1516
1517
1518<h4>Android Browser</h4>
1519
1520<p>The Browser application adds the following features to support web applications:</p>
1521<ul>
1522<li>Updated V8 JavaScript compiler for faster performance</li>
1523<li>Plus other notable enhancements carried over from <a
1524href=”{@docRoot}sdk/android-3.0.html”>Android
15253.0</a> are now available for handsets:
1526<ul>
1527<li>Support for fixed position elements on all pages</li>
1528<li><a href="http://dev.w3.org/2009/dap/camera/">HTML media capture</a></li>
1529<li><a href="http://dev.w3.org/geo/api/spec-source-orientation.html">Device orientation
1530events</a></li>
1531<li><a href="http://www.w3.org/TR/css3-3d-transforms/">CSS 3D transformations</a></li>
1532</ul>
1533</li>
1534</ul>
1535
1536
1537
1538<h3 id="Permissions">Permissions</h3>
1539
1540<p>The following are new permissions:</p>
1541<ul>
1542<li>{@link android.Manifest.permission#ADD_VOICEMAIL}: Allows a voicemail service to add voicemail
1543messages to the device.</li>
1544<li>{@link android.Manifest.permission#BIND_TEXT_SERVICE}: A service that implements {@link
1545android.service.textservice.SpellCheckerService} must require this permission for itself.</li>
1546<li>{@link android.Manifest.permission#BIND_VPN_SERVICE}: A service that implements {@link
1547android.net.VpnService} must require this permission for itself.</li>
1548<li>{@link android.Manifest.permission#READ_PROFILE}: Provides read access to the {@link
1549android.provider.ContactsContract.Profile} provider.</li>
1550<li>{@link android.Manifest.permission#WRITE_PROFILE}: Provides write access to the {@link
1551android.provider.ContactsContract.Profile} provider.</li>
1552</ul>
1553
1554
1555
1556<h3 id="DeviceFeatures">Device Features</h3>
1557
1558<p>The following are new device features:</p>
1559<ul>
1560<li>{@link android.content.pm.PackageManager#FEATURE_WIFI_DIRECT}: Declares that the application
1561uses
1562Wi-Fi for peer-to-peer communications.</li>
1563</ul>
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575<h2 id="api-diff">API Differences Report</h2>
1576
1577<p>For a detailed view of all API changes in Android {@sdkPlatformVersion} (API
1578Level
1579{@sdkPlatformApiLevel}), see the <a
1580href="{@docRoot}sdk/api_diff/{@sdkPlatformApiLevel}/changes.html">API
1581Differences Report</a>.</p>
1582
1583
1584
1585
1586
1587<h2 id="api-level">API Level</h2>
1588
1589<p>The Android {@sdkPlatformVersion} platform delivers an updated version of the framework API. The
1590Android {@sdkPlatformVersion} API is assigned an integer identifier &mdash;
1591<strong>{@sdkPlatformApiLevel}</strong> &mdash; that is stored in the system itself. This
1592identifier, called the "API Level", allows the system to correctly determine whether an application
1593is compatible with the system, prior to installing the application. </p>
1594
1595<p>To use APIs introduced in Android {@sdkPlatformVersion} in your application, you need compile the
1596application against the Android library that is provided in the Android {@sdkPlatformVersion} SDK
1597platform. Depending on your needs, you might also need to add an
1598<code>android:minSdkVersion="{@sdkPlatformApiLevel}"</code> attribute to the
1599<code>&lt;uses-sdk&gt;</code> element in the application's manifest.</p>
1600
1601<p>For more information about how to use API Level, see the <a
1602href="{@docRoot}guide/appendix/api-levels.html">API Levels</a> document. </p>
1603
1604
1605<h2 id="apps">Built-in Applications</h2>
1606
1607<p>The system image included in the downloadable platform provides these
1608built-in applications:</p>
1609
1610<table style="border:0;padding-bottom:0;margin-bottom:0;">
1611<tr>
1612<td style="border:0;padding-bottom:0;margin-bottom:0;">
1613<ul>
1614<li>API Demos</li>
1615<li>Browser</li>
1616<li>Calculator</li>
1617<li>Camera</li>
1618<li>Clock</li>
1619<li>Custom Locale</li>
1620<li>Dev Tools</li>
1621<li>Downloads</li>
1622<li>Email</li>
1623<li>Gallery</li>
1624</ul>
1625</td>
1626<td style="border:0;padding-bottom:0;margin-bottom:0;padding-left:5em;">
1627<ul>
1628<li>Gestures Builder</li>
1629<li>Messaging</li>
1630<li>Music</li>
1631<li>People</li>
1632<li>Phone</li>
1633<li>Search</li>
1634<li>Settings</li>
1635<li>Spare Parts</li>
1636<li>Speech Recorder</li>
1637<li>Widget Preview</li>
1638</ul>
1639</td>
1640</tr>
1641</table>
1642
1643
1644<h2 id="locs" style="margin-top:.75em;">Locales</h2>
1645
1646<p>The system image included in the downloadable SDK platform provides a variety
1647of
1648built-in locales. In some cases, region-specific strings are available for the
1649locales. In other cases, a default version of the language is used. The
1650languages that are available in the Android 3.0 system
1651image are listed below (with <em>language</em>_<em>country/region</em> locale
1652descriptor).</p>
1653
1654<table style="border:0;padding-bottom:0;margin-bottom:0;">
1655<tr>
1656<td style="border:0;padding-bottom:0;margin-bottom:0;">
1657<ul>
1658<li>Arabic, Egypt (ar_EG)</li>
1659<li>Arabic, Israel (ar_IL)</li>
1660<li>Bulgarian, Bulgaria (bg_BG)</li>
1661<li>Catalan, Spain (ca_ES)</li>
1662<li>Czech, Czech Republic (cs_CZ)</li>
1663<li>Danish, Denmark(da_DK)</li>
1664<li>German, Austria (de_AT)</li>
1665<li>German, Switzerland (de_CH)</li>
1666<li>German, Germany (de_DE)</li>
1667<li>German, Liechtenstein (de_LI)</li>
1668<li>Greek, Greece (el_GR)</li>
1669<li>English, Australia (en_AU)</li>
1670<li>English, Canada (en_CA)</li>
1671<li>English, Britain (en_GB)</li>
1672<li>English, Ireland (en_IE)</li>
1673<li>English, India (en_IN)</li>
1674<li>English, New Zealand (en_NZ)</li>
1675<li>English, Singapore(en_SG)</li>
1676<li>English, US (en_US)</li>
1677<li>English, Zimbabwe (en_ZA)</li>
1678<li>Spanish (es_ES)</li>
1679<li>Spanish, US (es_US)</li>
1680<li>Finnish, Finland (fi_FI)</li>
1681<li>French, Belgium (fr_BE)</li>
1682<li>French, Canada (fr_CA)</li>
1683<li>French, Switzerland (fr_CH)</li>
1684<li>French, France (fr_FR)</li>
1685<li>Hebrew, Israel (he_IL)</li>
1686<li>Hindi, India (hi_IN)</li>
1687</ul>
1688</td>
1689<td style="border:0;padding-bottom:0;margin-bottom:0;padding-left:5em;">
1690<li>Croatian, Croatia (hr_HR)</li>
1691<li>Hungarian, Hungary (hu_HU)</li>
1692<li>Indonesian, Indonesia (id_ID)</li>
1693<li>Italian, Switzerland (it_CH)</li>
1694<li>Italian, Italy (it_IT)</li>
1695<li>Japanese (ja_JP)</li>
1696<li>Korean (ko_KR)</li>
1697<li>Lithuanian, Lithuania (lt_LT)</li>
1698<li>Latvian, Latvia (lv_LV)</li>
1699<li>Norwegian bokmål, Norway (nb_NO)</li>
1700<li>Dutch, Belgium (nl_BE)</li>
1701<li>Dutch, Netherlands (nl_NL)</li>
1702<li>Polish (pl_PL)</li>
1703<li>Portuguese, Brazil (pt_BR)</li>
1704<li>Portuguese, Portugal (pt_PT)</li>
1705<li>Romanian, Romania (ro_RO)</li>
1706<li>Russian (ru_RU)</li></li>
1707<li>Slovak, Slovakia (sk_SK)</li>
1708<li>Slovenian, Slovenia (sl_SI)</li>
1709<li>Serbian (sr_RS)</li>
1710<li>Swedish, Sweden (sv_SE)</li>
1711<li>Thai, Thailand (th_TH)</li>
1712<li>Tagalog, Philippines (tl_PH)</li>
1713<li>Turkish, Turkey (tr_TR)</li>
1714<li>Ukrainian, Ukraine (uk_UA)</li>
1715<li>Vietnamese, Vietnam (vi_VN)</li>
1716<li>Chinese, PRC (zh_CN)</li>
1717<li>Chinese, Taiwan (zh_TW)</li>
1718</td>
1719</tr>
1720</table>
1721
1722<p class="note"><strong>Note:</strong> The Android platform may support more
1723locales than are included in the SDK system image. All of the supported locales
1724are available in the <a href="http://source.android.com/">Android Open Source
1725Project</a>.</p>
1726
1727<h2 id="skins">Emulator Skins</h2>
1728
1729<p>The downloadable platform includes the following emulator skin:</p>
1730
1731<ul>
1732 <li>
1733 WVGA800 (1280x800, extra high density, normal screen)
1734 </li>
1735</ul>
1736
1737<p>For more information about how to develop an application that displays
1738and functions properly on all Android-powered devices, see <a
1739href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple
1740Screens</a>.</p>