1 page.title=Android 4.2 APIs 2 excludeFromSuggestions=true 3 sdk.platform.version=4.2 4 sdk.platform.apiLevel=17 5 @jd:body 6 7 <div id="qv-wrapper"> 8 <div id="qv"> 9 10 <h2>In this document</h2> 11 <ol> 12 <li><a href="#Behaviors">Important Behavior Changes</a></li> 13 <li><a href="#Daydream">Daydream</a></li> 14 <li><a href="#SecondaryDisplays">Secondary Displays</a></li> 15 <li><a href="#Lockscreen">Lockscreen Widgets</a></li> 16 <li><a href="#MultipleUsers">Multiple Users</a></li> 17 <li><a href="#RTL">RTL Layout Support</a></li> 18 <li><a href="#NestedFragments">Nested Fragments</a></li> 19 <li><a href="#Renderscript">Renderscript</a></li> 20 </ol> 21 22 <h2>See also</h2> 23 <ol> 24 <li><a 25 href="{@docRoot}sdk/api_diff/17/changes.html">API 26 Differences Report »</a> </li> 27 </ol> 28 29 </div> 30 </div> 31 32 33 <p>API Level: 17</p> 34 35 <p>Android 4.2 ({@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}) 36 is an update to the Jelly Bean release that offers new features for users and app 37 developers. This document provides an introduction to the most notable and 38 useful new APIs for developers.</p> 39 40 <p>As an app developer, you should download the Android 4.2 system image and SDK platform from 41 the <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> as soon as possible. If you 42 dont have a device running Android 4.2 on which to test your app, use the Android 4.2 system 43 image to test your app on the <a href="{@docRoot}tools/devices/emulator.html">Android emulator</a>. 44 Then build your apps against the Android 4.2 platform to begin using the latest APIs.</p> 45 46 47 48 <div class="sidebox-wrapper"> 49 <div class="sidebox"> 50 51 <h3 id="ApiLevel">Declare your app API Level</h3> 52 53 <p>To better optimize your app for devices running Android {@sdkPlatformVersion}, 54 you should set your <a 55 href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code targetSdkVersion}</a> to 56 <code>"{@sdkPlatformApiLevel}"</code>, install it on an Android {@sdkPlatformVersion} system image, 57 test it, then publish an update with this change.</p> 58 59 <p>You 60 can use APIs in Android {@sdkPlatformVersion} while also supporting older versions by adding 61 conditions to your code that check for the system API level before executing 62 APIs not supported by your <a 63 href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a>. 64 To learn more about 65 maintaining backward-compatibility, read <a 66 href="{@docRoot}training/backward-compatible-ui/index.html">Creating Backward-Compatible 67 UIs</a>.</p> 68 69 <p>More information about how API levels work is available in <a 70 href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">What is API 71 Level?</a></p> 72 73 </div> 74 </div> 75 76 77 78 79 <h2 id="Behaviors">Important Behavior Changes</h2> 80 81 <p>If you have previously published an app for Android, be aware of the following 82 changes that might affect your apps behavior:</p> 83 84 <ul> 85 <li><b>Content providers</b> are no longer exported by default. That is, the default value 86 for the <a href="{@docRoot}guide/topics/manifest/provider-element.html#exported">{@code 87 android:exported}</a> attribute is now {@code false"}. If its important that other apps be 88 able to access your content provider, you must now explicitly set <a 89 href="{@docRoot}guide/topics/manifest/provider-element.html#exported">{@code 90 android:exported="true"}.</a> 91 <p>This change takes effect only if you set either <a 92 href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code 93 android:targetSdkVersion}</a> or <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code 94 android:minSdkVersion}</a> to 17 or higher. Otherwise, the default value is still {@code true"} 95 even when running on Android 4.2 and higher.</p> 96 </li> 97 98 <li>Compared to previous versions of Android, <b>user location</b> results may be less accurate 99 if your app requests the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} permission but 100 does not request the {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission. 101 <p>To meet the privacy expectations of users when your app requests permission for 102 coarse location (and not fine location), the system will not provide a user location estimate 103 thats more accurate than a city block.</p> 104 </li> 105 106 <li>Some <b>device settings</b> defined by {@link android.provider.Settings.System} are now 107 read-only. If your app attempts to write changes to settings defined in {@link 108 android.provider.Settings.System} that have moved to {@link android.provider.Settings.Global}, 109 the write operation will silently fail when running on Android 4.2 and higher. 110 <p>Even if your value for <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code 111 android:targetSdkVersion}</a> and <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code 112 android:minSdkVersion}</a> is lower than 17, your app is not able to modify the settings that have 113 moved to {@link android.provider.Settings.Global} when running on Android 4.2 and higher.</p> 114 </li> 115 116 <li>If your app uses {@link android.webkit.WebView}, Android 4.2 adds an additional layer of 117 security so you can more safely <b>bind JavaScript to your 118 Android code</b>. If you set your 119 <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code targetSdkVersion}</a> 120 to 17 or higher, you must now add the {@code @JavascriptInterface} annotation to any method that you 121 want available to your JavaScript (the method must also be public). If you do not provide the 122 annotation, the method is not accessible by a web page in your {@link android.webkit.WebView} 123 when running on Android 4.2 or higher. If you set the 124 <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code targetSdkVersion}</a> 125 to 16 or lower, the annotation is not required, but we recommend that you update your target version 126 and add the annotation for additional security. 127 <p>Read more about <a href="{@docRoot}guide/webapps/webview.html#BindingJavaScript">binding 128 JavaScript code to Android code</a>.</p></li> 129 </ul> 130 131 132 133 134 135 136 <h2 id="Daydream">Daydream</h2> 137 138 <p>Daydream is a new interactive screensaver mode for Android devices. It activates automatically 139 when the device is inserted into a dock or when the device is left idle while plugged in to a 140 charger (instead of turning the screen off). Daydream displays one dream at a time, which may 141 be a purely visual, passive display that dismisses upon touch, or may be interactive and responsive 142 to the full suite of input events. Your dreams run in your apps process and have full access to 143 the Android UI toolkit, including views, layouts, and animations, so they are more flexible and 144 powerful than either live wallpapers or app widgets.</p> 145 146 <p>You can create a dream for Daydream by implementing a subclass of {@link 147 android.service.dreams.DreamService}. The {@link android.service.dreams.DreamService} APIs are 148 designed to be similar to those of {@link android.app.Activity}. To specify the UI for your 149 dream, pass a layout resource ID or {@link android.view.View} to {@link 150 android.service.dreams.DreamService#setContentView setContentView()} at any point after you have 151 a window, such as from the {@link android.service.dreams.DreamService#onAttachedToWindow()} 152 callback.</p> 153 154 <p>The {@link android.service.dreams.DreamService} class provides other important lifecycle callback 155 methods on top of the base {@link android.app.Service} APIs, such as {@link 156 android.service.dreams.DreamService#onDreamingStarted()}, {@link 157 android.service.dreams.DreamService#onDreamingStopped()}, and {@link 158 android.service.dreams.DreamService#onDetachedFromWindow()}. 159 You cannot initiate a {@link android.service.dreams.DreamService} from your 160 app—it is launched automatically by the system.</p> 161 162 <p>If your dream is interactive, you can start an activity from the dream to send the user into 163 your apps full UI for more detail or control. You can use {@link 164 android.service.dreams.DreamService#finish()} to end the dream so the user can see the 165 new Activity.</p> 166 167 <p>To make your daydream available to the system, declare your {@link 168 android.service.dreams.DreamService} with a <a 169 href="{@docRoot}guide/topics/manifest/service-element.html">{@code <service>}</a> element 170 in your manifest file. You must then include an intent filter with the action {@code 171 "android.service.dreams.DreamService"}. For example:</p> 172 173 <pre> 174 <service android:name=".MyDream" android:exported="true" 175 android:icon="@drawable/dream_icon" android:label="@string/dream_label" > 176 <intent-filter> 177 <action android:name="android.service.dreams.DreamService" /> 178 <category android:name="android.intent.category.DEFAULT" /> 179 </intent-filter> 180 </service> 181 </pre> 182 183 <p>There are some other useful methods in {@link android.service.dreams.DreamService} 184 to be aware of:</p> 185 186 <ul> 187 <li>{@link android.service.dreams.DreamService#setInteractive(boolean)} controls whether 188 the dream receives input events or exits immediately upon user input. If the dream is 189 interactive, the user may use the <em>Back</em> or <em>Home</em> buttons to exit the dream or you can call 190 {@link android.service.dreams.DreamService#finish()} to stop the dream.</li> 191 <li>If you want a fully immersive display, you can call {@link 192 android.service.dreams.DreamService#setFullscreen 193 setFullscreen()} to hide the status bar.</li> 194 <li>Before Daydream starts, the display dims to signal to the user that the idle timeout 195 is approaching. Calling {@link android.service.dreams.DreamService#setScreenBright 196 setScreenBright(true)} allows you to instead set the display at its usual brightness.</li> 197 </ul> 198 199 <p>For more information, see the {@link android.service.dreams.DreamService} documentation.</p> 200 201 202 203 204 205 206 207 208 209 210 211 <h2 id="SecondaryDisplays">Secondary Displays</h2> 212 213 <p>Android now allows your app to display unique content on additional screens that are connected 214 to the users device over either a wired connection or Wi-Fi. 215 To create unique content for a secondary display, extend the {@link android.app.Presentation} 216 class and implement the {@link android.app.Presentation#onCreate onCreate()} callback. Within 217 {@link android.app.Presentation#onCreate onCreate()}, specify your UI for the secondary display 218 by calling {@link android.app.Presentation#setContentView setContentView()}. 219 As an extension of the {@link android.app.Dialog} class, the {@link 220 android.app.Presentation} class provides the region in which your app can display a unique UI on the 221 secondary display.</p> 222 223 <p>To detect secondary displays where you can display your {@link android.app.Presentation}, 224 use either the {@link android.hardware.display.DisplayManager} or {@link android.media.MediaRouter} 225 APIs. While the {@link android.hardware.display.DisplayManager} APIs allow you to enumerate 226 multiple displays that may be connected at once, you should usually use {@link 227 android.media.MediaRouter} instead to quickly access the systems default display for 228 presentations.</p> 229 230 <p>To get the default display for your presentation, call {@link 231 android.media.MediaRouter#getSelectedRoute MediaRouter.getSelectedRoute()} and pass it 232 {@link android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO}. This returns a {@link 233 android.media.MediaRouter.RouteInfo} object that describes the systems currently selected route 234 for video presentations. If the {@link android.media.MediaRouter.RouteInfo} is not null, call 235 {@link android.media.MediaRouter.RouteInfo#getPresentationDisplay()} to get the {@link 236 android.view.Display} representing the connected display.</p> 237 238 <p>You can then display your presentation by passing the {@link android.view.Display} object 239 to a constructor for your {@link android.app.Presentation} class. Your presentation will now 240 appear on the secondary display.</p> 241 242 <p>To detect at runtime when a new display has been connected, create an instance of {@link 243 android.media.MediaRouter.SimpleCallback} in which you implement the {@link 244 android.media.MediaRouter.SimpleCallback#onRoutePresentationDisplayChanged 245 onRoutePresentationDisplayChanged()} callback method, which the system will call when a new 246 presentation display is connected. Then register the {@link 247 android.media.MediaRouter.SimpleCallback} by passing it to {@link 248 android.media.MediaRouter#addCallback MediaRouter.addCallback()} along with the {@link 249 android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO} route type. When you receive a call to 250 {@link android.media.MediaRouter.SimpleCallback#onRoutePresentationDisplayChanged 251 onRoutePresentationDisplayChanged()}, simply call {@link 252 android.media.MediaRouter#getSelectedRoute MediaRouter.getSelectedRoute()} as mentioned above.</p> 253 254 <p>To further optimize the UI in your {@link android.app.Presentation} for 255 secondary screens, you can apply 256 a different theme by specifying the {@link 257 android.R.attr#presentationTheme android:presentationTheme} attribute in the <a 258 href="{@docRoot}guide/topics/resources/style-resource.html">{@code <style>}</a> that youve 259 applied to your application or activity.</p> 260 261 <p>Keep in mind that screens connected to the users device often have a larger screen size and 262 likely a different screen density. Because the screen characteristics may different, you should 263 provide resources that are optimized specifically for such larger displays. If you need 264 to request additional resources from your {@link 265 android.app.Presentation}, call {@link android.app.Presentation#getContext()}{@link 266 android.content.Context#getResources .getResources()} to get the {@link 267 android.content.res.Resources} object corresponding to the display. This provides 268 the appropriate resources from your app that are best suited for the 269 secondary display's screen size and density.</p> 270 271 <p>For more information and some code samples, see the {@link android.app.Presentation} 272 class documentation.</p> 273 274 275 276 277 278 279 280 281 282 283 <h2 id="Lockscreen">Lockscreen Widgets</h2> 284 285 <p>Android now allows users to add app widgets to the lock screen. To make your <a 286 href="{@docRoot}guide/topics/appwidgets/index.html">App Widget</a> available for use on the 287 lock screen, add the {@link android.appwidget.AppWidgetProviderInfo#widgetCategory 288 android:widgetCategory} attribute to your XML file that specifies the {@link 289 android.appwidget.AppWidgetProviderInfo}. This attribute supports two values: {@code home_screen} 290 and {@code keyguard}. By default, the attribute is set to {@code home_screen} so users can add your 291 app widget to the Home screen. If you want your app widget to be also available on the lock 292 screen, add the {@code keyguard} value:</p> 293 294 <pre> 295 <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 296 ... 297 android:widgetCategory="keyguard|home_screen"> 298 </appwidget-provider> 299 </pre> 300 301 <p>You should also specify an initial layout for your app widget when on the lock screen with 302 the {@link android.appwidget.AppWidgetProviderInfo#initialKeyguardLayout 303 android:initialKeyguardLayout} attribute. This works the same way as the {@link 304 android.appwidget.AppWidgetProviderInfo#initialLayout android:initialLayout}, in that it provides 305 a layout that can appear immediately until your app widget is initialized and able to update the 306 layout.</p> 307 308 <p>For more information about building app widgets for the lock screen, including to properly 309 size your app widget when on the lock screen, see the <a 310 href="{@docRoot}guide/topics/appwidgets/index.html#lockscreen">App Widgets</a> guide.</p> 311 312 313 314 315 316 317 318 <h2 id="MultipleUsers">Multiple Users</h2> 319 320 <p>Android now allows multiple user spaces on shareable devices such as tablets. Each user on a 321 device has his or her own set of accounts, apps, system settings, files, and any other 322 user-associated data.</p> 323 324 <p>As an app developer, theres nothing different you need to do in order for your app to work 325 properly with multiple users on a single device. Regardless of how many users may exist on a 326 device, the data your app saves for a given user is kept separate from the data your app saves 327 for other users. The system keeps track of which user data belongs to the user process in which 328 your app is running and provides your app access to only that users data and does not allow 329 access to other users data.</p> 330 331 <h3>Saving data in a multi-user environment</h3> 332 333 <p>Whenever your app saves user preferences, creates a database, or writes a file to the users 334 internal or external storage space, that data is accessible only while running as that user.</p> 335 336 <p>To be certain that your app behaves properly in a multi-user environment, do not refer to your 337 internal app directory or external storage location using hard-coded paths and instead always use 338 the appropriate APIs:</p> 339 <ul> 340 <li>For access to internal storage, use {@link android.content.Context#getFilesDir()}, {@link 341 android.content.Context#getCacheDir()}, or {@link android.content.Context#openFileOutput 342 openFileOutput()}.</li> 343 <li>For access to external storage, use {@link android.content.Context#getExternalFilesDir 344 getExternalFilesDir()} or {@link android.os.Environment#getExternalStoragePublicDirectory 345 getExternalStoragePublicDirectory()}. 346 </ul> 347 348 <p>No matter which of these APIs you use to save data for a given user, the data will not be 349 accessible while running as a different user. From your apps point of view, each user is running 350 on a completely separate device.</p> 351 352 <h3>Identifying users in a multi-user environment</h3> 353 354 <p>If your app wants to identify unique users such as to gather analytics or create other account 355 associations, you should follow the recommended practices for <a 356 href="http://android-developers.blogspot.com/2011/03/identifying-app-installations.html">identifying 357 unique installations</a>. By creating a new {@link java.util.UUID} when your app starts for the 358 first time, youre certain to obtain a unique ID for tracking each user, regardless of how many 359 users install your app on a single device. Alternatively, you can save a local token fetched from 360 your server or use the registrations ID provided by <a 361 href="{@docRoot}google/gcm/index.html">Google Cloud Messaging</a>.</p> 362 363 <p>Beware that if your app requests one of the hardware device identifiers (such as the WiFi MAC 364 address, the {@link android.os.Build#SERIAL} number, or the {@link 365 android.provider.Settings.Secure#ANDROID_ID} number), they will provide the same value for each 366 user because these identifiers are tied to the hardware and not the user. Not to mention the other 367 problems these identifiers introduce as discussed in the <a 368 href="http://android-developers.blogspot.com/2011/03/identifying-app-installations.html">Identifying 369 App Installations</a> blog post.</p> 370 371 <h3>New Global Settings</h3> 372 373 <p>The system settings have been updated to support multiple users with the addition of {@link 374 android.provider.Settings.Global}. This collection of settings is similar to {@link 375 android.provider.Settings.Secure} settings because they are read-only, but applies globally across 376 all user spaces on the device.</p> 377 378 <p>Several existing settings were relocated here from either {@link 379 android.provider.Settings.System} or {@link android.provider.Settings.Secure}. If your app is 380 currently making changes to settings previously defined in {@link android.provider.Settings.System} 381 (such as {@link android.provider.Settings.System#AIRPLANE_MODE_ON}), then you should expect that 382 doing so will no longer work on a device running Android 4.2 or higher if those settings were 383 moved to {@link android.provider.Settings.Global}. You can continue to read settings that are in 384 {@link android.provider.Settings.Global}, but because the settings are no longer considered safe 385 for apps to change, attempting to do so will fail silently and the system will write a warning to 386 the system log when running your app on Android 4.2 or higher.</p> 387 388 389 390 391 392 393 394 395 396 <h2 id="RTL">RTL Layout Support</h2> 397 398 <p>Android now offers several APIs that allow you to build user interfaces that gracefully 399 transform layout orientation to support languages that use right-to-left (RTL) UIs and reading 400 direction, such as Arabic and Hebrew.</p> 401 402 <p>To begin supporting RTL layouts in your app, set the {@link android.R.attr#supportsRtl 403 android:supportsRtl} attribute to the {@code <application>} element in your manifest file 404 and set it {@code true"}. Once you enable this, the system will enable various RTL APIs to 405 display your app with RTL layouts. For instance, the action bar will show the icon and title 406 on the right side and action buttons on the left, and any layouts youve created with the 407 framework-provided {@link android.view.View} classes will also be reversed.</p> 408 409 <p>If you need to further optimize the appearance of your app when displayed with an RTL layout, 410 there are two basic levels of optimization:</p> 411 412 <ol> 413 <li>Convert left- and right-oriented layout properties to start- and end-oriented layout 414 properties. 415 <p>For example, use {@link android.R.attr#layout_marginStart android:layout_marginStart} 416 in place of {@code android:layout_marginLeft} and {@link android.R.attr#layout_marginEnd 417 android:layout_marginEnd} in place of {@code android:layout_marginRight}. 418 <p>The {@link android.widget.RelativeLayout} class also provides the corresponding layout 419 attributes to replace left/right positions, such as {@code android:layout_alignParentStart} to 420 replace {@code android:layout_alignParentLeft} and {@code android:layout_toStartOf} instead of 421 {@code android:layout_toLeftOf}. 422 </li> 423 <li>Or to provide complete optimization for RTL layouts, you can provide entirely separate 424 layout files using the {@code ldrtl} resource qualifier ({@code ldrtl} stands for 425 layout-direction-right-to-left}). For example, you can save your default layout files in 426 {@code res/layout/} and your RTL optimized layouts in {@code res/layout-ldrtl/}. 427 <p>The {@code ldrtl} qualifier is great for drawable resources, so that you can provide 428 graphics that are oriented in the direction corresponding to the reading direction.</p> 429 </li> 430 </ol> 431 432 <p>Various other APIs are available across the framework to support RTL layouts, such as in 433 the {@link android.view.View} class so that you can implement the proper behaviors for custom 434 views and in {@link android.content.res.Configuration} to query the current layout direction.</p> 435 436 <p><strong>Note:</strong> If you are using SQlite and have tables or column names that are 437 number only," be 438 careful: using <a href="{@docRoot}reference/java/lang/String.html#format(String, Object...)">{@code 439 String.format(String, Object...)}</a> can lead to errors where the numbers 440 have been converted to their Arabic equivalents if your device has been set to the Arabic locale. 441 You must use <a href="{@docRoot}reference/java/lang/String.html#format(Locale,String,Object...)">{@code 442 String.format(Locale,String,Object...)}</a> to ensure numbers are 443 preserved as ASCII. Also use <a href="{@docRoot}reference/java/lang/String.html#format(String,int)">{@code 444 String.format("%d", int)}</a> instead of using 445 <a href="{@docRoot}reference/java/lang/String.html#valueOf(int)">{@code String.valueOf(int)}</a> for 446 formatting numbers.</p> 447 448 449 450 451 452 453 454 455 456 457 458 459 460 <h2 id="NestedFragments">Nested Fragments</h2> 461 462 <p>You can now embed fragments inside fragments. This is useful for a variety of situations in 463 which you want to place dynamic and re-usable UI components into a UI component that is itself 464 dynamic and re-usable. For example, if you use {@link android.support.v4.view.ViewPager} to 465 create fragments that swipe left and right and consume a majority of the screen space, you can 466 now insert fragments into each fragment page.</p> 467 468 <p>To nest a fragment, simply call {@link android.app.Fragment#getChildFragmentManager()} on 469 the {@link android.app.Fragment} in which you want to add a fragment. This returns a {@link 470 android.app.FragmentManager} that you can use like you normally do from the top-level activity 471 to create fragment transactions. For example, heres some code that adds a fragment from within 472 an existing {@link android.app.Fragment} class:</p> 473 474 <pre> 475 Fragment videoFragment = new VideoPlayerFragment(); 476 FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); 477 transaction.add(R.id.video_fragment, videoFragment).commit(); 478 </pre> 479 480 <p>From within a nested fragment, you can get a reference to the parent fragment by calling 481 {@link android.app.Fragment#getParentFragment()}.</p> 482 483 <p>The Android Support Library also now supports nested fragments, so you can implement nested 484 fragment designs on Android 1.6 and higher.</p> 485 486 <p><strong>Note:</strong> You cannot inflate a layout into a fragment when that layout 487 includes a {@code <fragment>}. Nested fragments are only supported when added to a 488 fragment dynamically.</p> 489 490 491 492 493 494 495 <h2 id="Renderscript">Renderscript</h2> 496 497 <p>Renderscript computation functionality has been enhanced with the following features:</p> 498 <dl> 499 <dt><b>Script intrinsics</b></dt> 500 <dd><p>You can use Renderscript's built-in script intrinsics that implement 501 common operations for you such as:</p> 502 <ul> 503 <li>{@link android.renderscript.ScriptIntrinsicBlend Blends}</li> 504 <li>{@link android.renderscript.ScriptIntrinsicBlur Blur}</li> 505 <li>{@link android.renderscript.ScriptIntrinsicColorMatrix Color matrix}</li> 506 <li>{@link android.renderscript.ScriptIntrinsicConvolve3x3 3x3 convolve}</li> 507 <li>{@link android.renderscript.ScriptIntrinsicConvolve5x5 5x5 convolve}</li> 508 <li>{@link android.renderscript.ScriptIntrinsicLUT Per-channel lookup table}</li> 509 <li>{@link android.renderscript.ScriptIntrinsicYuvToRGB Converting an Android YUV buffer to RGB}</li> 510 </ul> 511 <p>To use a script intrinsic, call the static <code>create()</code> method of each instrinsic 512 to create an instance of the script. You then call the available <code>set()</code> 513 methods of each script intrinsic to set any necessary inputs and options. 514 Finally, call the {@link android.renderscript.ScriptC#forEach forEach()}</code> 515 method to execute the script.</p> 516 </dd> 517 518 519 <dt><b>Script Groups</b></dt> 520 <dd> 521 <p>{@link android.renderscript.ScriptGroup}s allow you to chain together related Renderscript 522 scripts and execute them with one call.</p> 523 524 <p>Use a {@link android.renderscript.ScriptGroup.Builder} to add all of the scripts to the group 525 by calling {@link android.renderscript.ScriptGroup.Builder#addKernel addKernel()}. Once you 526 add all the scripts, create the connections between the 527 scripts by calling {@link android.renderscript.ScriptGroup.Builder#addConnection addConnection()}. 528 When you are done adding the connections, call {@link android.renderscript.ScriptGroup.Builder#create create()} 529 to create the script group. Before executing the script group, specify the input 530 {@link android.renderscript.Allocation} and initial script to run with the 531 {@link android.renderscript.ScriptGroup#setInput} method and provide the output 532 {@link android.renderscript.Allocation} where the result will be written to and final script to 533 run with {@link android.renderscript.ScriptGroup#setOutput setOutput()}. Finally, call 534 {@link android.renderscript.ScriptGroup#execute execute()} to run the script group. 535 </p> 536 </dd> 537 538 <dt><b>Filterscript</b></dt> 539 <dd> 540 <p>Filterscript defines constraints on the existing Renderscript APIs that allow the resulting code to run 541 on a wider variety of processors (CPUs, GPUs, and DSPs). To create Filterscript files, create <code>.fs</code> 542 files instead of <code>.rs</code> files, and specify <code>#pragma rs_fp_relaxed</code> to 543 tell the Renderscript runtime your scripts do not require strict IEEE 754-2008 floating point precision. 544 This precision allows flush-to-zero for denorms and round-towards-zero. In addition, your Filterscript 545 scripts must not use 32-bit built-in types and must specify a custom root function by using the 546 <code>__attribute__((kernel))</code> attribute because Filterscript does not support pointers, which 547 the default signature of the <code>root()</code> function defines.</p> 548 </dd> 549 550 </dl> 551 552 <p class="note"><strong>Note:</strong> Although Filterscript support is in the platform, developer 553 support will be available in ADT and SDK Tools Release 21.0.1. </p> 554 555 556 <p>For a detailed view of all API changes in Android 4.2, see the 557 <a href="{@docRoot}sdk/api_diff/17/changes.html">API Differences Report</a>.</p> 558 559 560 561