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