blob: 09227f2515210c2fcdc6d45e5166620e75fc386b [file] [log] [blame]
Dirk Doughertycf65e4842016-03-07 22:31:57 -08001page.title=Android N for Developers
Dirk Dougherty43eb9512016-03-03 14:53:16 -08002meta.tags="preview", "androidn"
3page.tags="preview", "developer preview"
Dirk Doughertya6495a922016-03-04 15:21:59 -08004page.image=images/cards/card-n-apis_2x.png
Dirk Dougherty5748bc42016-02-06 18:24:32 -08005@jd:body
6
Dirk Doughertycf65e4842016-03-07 22:31:57 -08007
8
9
10<div id="qv-wrapper">
11<div id="qv">
12 <h2>Key developer features</h2>
13 <ol>
14 <ul style="list-style-type:none;">
15 <li><a href="#multi-window_support">Multi-window support</a></li>
16 <li><a href="#notification_enhancements">Notifications</a></li>
Dirk Doughertycf65e4842016-03-07 22:31:57 -080017 <li><a href="#jit_aot">JIT/AOT compilation</a></li>
18 <li><a href="#quick_path_to_app_install">Quick path to app install</a></li>
19 <li><a href="#doze_on_the_go">Doze on the go</a></li>
20 <li><a href="#background_optimizations">Background optimizations</a></li>
Dirk Dougherty59428922016-03-10 18:54:49 -080021 <li><a href="#data_saver">Data Saver</a></li>
Andrew Solovay097b1152016-04-06 17:33:00 -070022 <li><a href="#vulkan">Vulkan API</a></li>
Dirk Dougherty59428922016-03-10 18:54:49 -080023 <li><a href="#tile_api">Quick Settings Tile API</a></li>
24 <li><a href="#number-blocking">Number-blocking</a></li>
25 <li><a href="#call_screening">Call screening</a></li>
26 <li><a href="#multi-locale_languages">Locales and languages</a></li>
Eric Schmidt700127a2016-05-12 16:29:18 -070027 <li><a href="#emoji">New Emojis</a></li>
Dirk Dougherty59428922016-03-10 18:54:49 -080028 <li><a href="#icu4">ICU4J APIs in Android</a></li>
29 <li><a href="#gles_32">OpenGL ES 3.2 API</a></li>
30 <li><a href="#android_tv_recording">Android TV recording</a></li>
31 <li><a href="#android_for_work">Android for Work</a></li>
32 <li><a href="#accessibility_enhancements">Accessibility</a></li>
33 <li><a href="#direct_boot">Direct Boot</a></li>
34 <li><a href="#key_attestation">Key Attestation</a></li>
35 <li><a href="#network_security_config">Network Security Config</a></li>
36 <li><a href="#default_trusted_ca">Default Trusted CA</a></li>
Kevin Hufnaglea6a568d2016-04-11 14:11:45 -070037 <li><a href="#apk_signature_v2">APK signature scheme v2</a></li>
Dirk Dougherty59428922016-03-10 18:54:49 -080038 <li><a href="#scoped_directory_access">Scoped directory access</a></li>
David Friedman93970ba2016-05-13 01:23:13 -070039 <li><a href="#keyboard_shortcuts_helper">Keyboard Shortcuts Helper</a></li>
40 <li><a href="#sustained_performance_api">Sustained Performance API</a></li>
Andrew Solovay097b1152016-04-06 17:33:00 -070041 <li><a href="#print_svc">Print service enhancements</a></li>
Eric Schmidt186fada2016-04-27 11:48:22 -070042 <li><a href="#virtual_files">Virtual Files</a></li>
David Friedman93970ba2016-05-13 01:23:13 -070043 <li><a href="#framemetrics_api">FrameMetricsListener API</a></li>
Dirk Doughertycf65e4842016-03-07 22:31:57 -080044 </ol>
45</div>
46</div>
47
48
49
50<p>Android N is still in active development, but you can try it
51now as part of the N Developer Preview. The sections below highlight some of
52the new features for developers. </p>
53
Andrew Solovay9b218572016-03-09 11:17:07 -080054<p>
55 Make sure to check out the <a href=
56 "{@docRoot}preview/behavior-changes.html">Behavior Changes</a> to learn about
57 areas where platform changes may affect your apps, take a look at the
58 developer guides to learn more about key features, and download the <a href=
59 "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a> for details on
60 new APIs.
61</p>
Dirk Doughertycf65e4842016-03-07 22:31:57 -080062
63<h2 id="multi-window_support">Multi-window support</h2>
64
65
66<p>In Android N, we're introducing a new and much-requested multitasking feature
67into the platform &mdash; multi-window support. </p>
68
69 <p>Users can now pop open two apps on the screen at once. </p>
70 <ul>
71 <li>On phones and tablets
72running Android N, users can run two apps side-by-side or
73one-above-the-other in splitscreen mode. Users can resize the apps by dragging
74the divider between them. </li>
75
Andrew Solovay9b218572016-03-09 11:17:07 -080076<li>On Android TV devices, apps can put themselves in <a
77href="{@docRoot}preview/features/picture-in-picture.html">picture-in-picture
78mode</a>, allowing them to continue showing content while the user browses or
Daniel Yu0ab19aa2016-03-14 15:35:38 -070079interacts with other apps.</li>
Dirk Doughertycf65e4842016-03-07 22:31:57 -080080 </ul>
81
Dirk Doughertycf65e4842016-03-07 22:31:57 -080082<div class="col-4of10">
Dirk Dougherty59428922016-03-10 18:54:49 -080083<img src="{@docRoot}preview/images/mw-portrait.png" alt="" style="height:460px;padding-left:1em;"
Dirk Doughertycf65e4842016-03-07 22:31:57 -080084 id="img-split-screen" />
85<p class="img-caption">
Dirk Dougherty59428922016-03-10 18:54:49 -080086 <strong>Figure 1.</strong> Apps running in split-screen mode.
Dirk Dougherty5748bc42016-02-06 18:24:32 -080087</p>
Dirk Doughertycf65e4842016-03-07 22:31:57 -080088 </div>
89
Dirk Doughertycf65e4842016-03-07 22:31:57 -080090<p>Especially on tablets and other larger-screen devices, multi-window support
91gives you new ways to engage users. You can even enable drag-and-drop in
92your app to let users conveniently drag content to or from your app &mdash; a great
93way to enhance your user experience. </p>
94
95<p>It's straightforward to add multi-window support to your app and configure how it
96handles multi-window display. For example, you can specify your activity's
97minimum allowable dimensions, preventing users from resizing the activity below
98that size. You can also disable multi-window display for your app, which
99 ensures that the system will only show your app in full-screen mode.</p>
100
Andrew Solovay9b218572016-03-09 11:17:07 -0800101<p>
102 For more information, see the <a href=
103 "{@docRoot}preview/features/multi-window.html">Multi-Window Support</a>
104 developer documentation.
105</p>
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800106
107<h2 id="notification_enhancements">Notification enhancements</h2>
108
109<p>In Android N we've redesigned notifications to make them easier and faster to
110use. Some of the changes include:</p>
111
112<ul>
Andrew Solovay9b218572016-03-09 11:17:07 -0800113 <li>
114 <strong>Template updates</strong>: We're updating notification templates to
115 put a new emphasis on hero image and avatar. Developers will be able to
116 take advantage of the new templates with minimal adjustments in their code.
117 </li>
118
119 <li>
Eric Schmidt57a83b52016-05-10 12:37:38 -0700120 <strong>Message style customization</strong>: You can customize more of the
121 user interface labels associated with your notifications using the
122 <code>MessageStyle</code> class. You can configure the message, conversation
123 title, and content view.
124 </li>
125
126 <li>
Andrew Solovay9b218572016-03-09 11:17:07 -0800127 <strong>Bundled notifications</strong>: The system can group messages
128 together, for example by message topic, and display the group. A user can
129 take actions, such as Dismiss or Archive, on them in place. If you’ve
130 implemented notifications for Android Wear, you’ll already be familiar with
Andrew Solovay069ac632016-03-11 11:23:27 -0800131 this model.
Andrew Solovay9b218572016-03-09 11:17:07 -0800132 </li>
133
134 <li>
135 <strong>Direct reply</strong>: For real-time communication apps, the
136 Android system supports inline replies so that users can quickly respond to
137 an SMS or text message directly within the notification interface.
138 </li>
139
140 <li>
141 <strong>Custom views</strong>: Two new APIs enable you to leverage system
142 decorations, such as notification headers and actions, when using custom
143 views in notifications.
144 </li>
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800145</ul>
146
147<div class="col-4of12">
Andrew Solovay9b218572016-03-09 11:17:07 -0800148 <img src="{@docRoot}preview/images/notifications-1.png" alt=""
149 style="padding:.5em;max-width:226px">
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800150</div>
Andrew Solovay9b218572016-03-09 11:17:07 -0800151
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800152<div class="col-4of12">
Andrew Solovay9b218572016-03-09 11:17:07 -0800153 <img src="{@docRoot}preview/images/notifications-3.png" alt=""
154 style="padding:.5em;max-width:226px">
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800155</div>
Andrew Solovay9b218572016-03-09 11:17:07 -0800156
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800157<div class="col-4of12">
Andrew Solovay9b218572016-03-09 11:17:07 -0800158 <img src="{@docRoot}preview/images/notifications-2.png" alt=""
159 style="padding:.5em;max-width:226px">
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800160</div>
161
162
163<p class="img-caption">
Adarsh Fernando37601562016-03-09 09:53:57 -0800164 <strong>Figure 2.</strong> Bundled notifications and direct reply.
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800165</p>
166
Andrew Solovay9b218572016-03-09 11:17:07 -0800167<p>To learn how to implement the new features, see the
168 <a href="{@docRoot}preview/features/notification-updates.html">Notifications</a>
169 guide.</p>
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800170
171
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800172
173<h2 id="jit_aot">Profile-guided JIT/AOT compilation</h2>
174
175<p>In Android N, we've added a Just in Time (JIT) compiler with code profiling to
176ART, which lets it constantly improve the performance of Android apps as they
177run. The JIT compiler complements ART's current Ahead of Time (AOT) compiler
178and helps improve runtime performance, save storage space, and speed up app
179updates and system updates.</p>
180
181<p>Profile-guided compilation lets ART manage the AOT/JIT compilation for each app
182according to its actual usage, as well as conditions on the device. For
183example, ART maintains a profile of each app's hot methods and can precompile
184and cache those methods for best performance. It leaves other parts of the app
185uncompiled until they are actually used.</p>
186
187<p>Besides improving performance for key parts of the app, profile-guided
188compilation helps reduce an app's overall RAM footprint, including associated
189binaries. This feature is especially important on low-memory devices.</p>
190
191<p>ART manages profile-guided compilation in a way that minimizes impact on the
192device battery. It does precompilation only when then the device is idle and
193charging, saving time and battery by doing that work in advance.</p>
194
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800195<h2 id="quick_path_to_app_install">Quick path to app install</h2>
196
197<p>One of the most tangible benefits of ART's JIT compiler is the speed of app
198installs and system updates. Even large apps that required several minutes to
199optimize and install in Android 6.0 can now install in just a matter of
200seconds. System updates are also faster, since there's no more optimizing step. </p>
201
202<h2 id="doze_on_the_go">Doze on the go...</h2>
203
204<p>Android 6.0 introduced Doze, a system mode that saves battery by deferring
205apps' CPU and network activities when the device is idle, such as when it's
206sitting on a table or in a drawer. </p>
207
208<p>Now in Android N, Doze takes a step further and saves battery while on the go.
209Any time the screen is off for a period of time and the device is unplugged,
210Doze applies a subset of the familiar CPU and network restrictions to apps.
211This means users can save battery even when carrying their devices in their
212pockets.</p>
213
214
Dirk Dougherty59428922016-03-10 18:54:49 -0800215<img src="/preview/images/doze-diagram-1.png"
216 alt="" id="figure1" />
217<p class="img-caption">
Andrew Solovay069ac632016-03-11 11:23:27 -0800218 <strong>Figure 3.</strong> Doze now applies
Dirk Dougherty59428922016-03-10 18:54:49 -0800219 restrictions to improve battery life even when the device is not stationary.
220</p>
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800221
222
223<p>A short time after the screen turns off while the device is on battery, Doze
224restricts network access and defers jobs and syncs. During brief maintenance
225windows, applications are allowed network access and any of their deferred
226jobs/syncs are executed. Turning the screen on or plugging in the device brings
227the device out of Doze.</p>
228
229<p>When the device is stationary again, with screen off and on battery for a
230period of time, Doze applies the full CPU and network restrictions on {@link
231android.os.PowerManager.WakeLock}, {@link android.app.AlarmManager} alarms, and
232GPS/Wi-Fi scans.</p>
233
234<p>The best practices for adapting your app to Doze are the same whether the
235device is moving or not, so if you already updated your app to gracefully
236handle Doze, you're all set. If not, start <a
Andrew Solovay9b218572016-03-09 11:17:07 -0800237href="{@docRoot}training/monitoring-device-state/doze-standby.html#assessing_your_app">adapting
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800238your app to Doze</a> now.</p>
239
240<h2 id="background_optimizations">Project Svelte: Background optimizations</h2>
241
242<p>Project Svelte is an ongoing effort to minimize RAM use by system and apps
243across the range of Android devices in the ecosystem. In Android N, Project
244Svelte is focused on optimizing the way apps run in the background. </p>
245
246<p>Background processing is an essential part of most apps. When handled right, it
247can make your user experience amazing &mdash; immediate, fast, and context-aware.
248When not handled right, background processing can needlessly consume RAM (and
249battery) and affect system performance for other apps. </p>
250
Andrew Solovayd6a6f962016-03-10 15:01:29 -0800251<p>Since Android 5.0, {@link android.app.job.JobScheduler} has been the
252preferred way of performing background work in a way that's good
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800253for users. Apps can schedule jobs while letting the system optimize based on
254memory, power, and connectivity conditions. JobScheduler offers control and
255simplicity, and we want all apps to use it. </p>
256
Andrew Solovay9b218572016-03-09 11:17:07 -0800257<p>
258 Another good option is <a href=
259 "https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmNetworkManager">
260 <code>GCMNetworkManager</code></a>, part of Google Play Services, which
261 offers similar job scheduling with compatibility across legacy versions of
262 Android.
263</p>
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800264
Andrew Solovayd6a6f962016-03-10 15:01:29 -0800265<p>We're continuing to extend <code>JobScheduler</code> and
266<code>GCMNetworkManager</code> to meet more of
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800267your use cases &mdash; for example, in Android N you can now schedule background
268work based on changes in Content Providers. At the same time we're starting to
269deprecate some of the older patterns that can reduce system performance,
270especially on low-memory devices.</p>
271
272<p>In Android N we're removing three commonly-used implicit broadcasts &mdash;
Adarsh Fernando37601562016-03-09 09:53:57 -0800273 {@link android.net.ConnectivityManager#CONNECTIVITY_ACTION}, {@link
274 android.hardware.Camera#ACTION_NEW_PICTURE}, and {@link
275 android.hardware.Camera#ACTION_NEW_VIDEO} &mdash; since those can wake the
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800276background processes of multiple apps at once and strain memory and battery. If
277your app is receiving these, take advantage of the N Developer Preview to
278 migrate to <code>JobScheduler</code> and related APIs instead. </p>
279
Andrew Solovay9b218572016-03-09 11:17:07 -0800280<p>
281 Take a look at the <a href=
282 "{@docRoot}preview/features/background-optimization.html">Background
283 Optimizations</a> documentation for details.
284</p>
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800285
Dirk Dougherty59428922016-03-10 18:54:49 -0800286
287<h2 id="data_saver">Data Saver</h2>
288
289<div class="col-5of12" style="margin-right:1.5em;">
290<img src="{@docRoot}preview/images/datasaver.png" style="border:2px solid #ddd">
291
292<p class="img-caption" style="padding-right:2em;">
293 <strong>Figure 4.</strong> Data Saver in Settings.
294</p>
295 </div>
296
297<p>Over the life of a mobile device, the cost of a cellular data plan typically
298exceeds the cost of the device itself. For many users, cellular data is an
299expensive resource that they want to conserve. </p>
300
301<p>Android N introduces Data Saver mode, a new system service that helps reduce
302cellular data use by apps, whether roaming, near the end of the billing cycle,
303or on a small prepaid data pack. Data Saver gives users control over how apps
304use cellular data and lets developers provide more efficient service when Data
305Saver is on. </p>
306
307<p>When a user enables Data Saver in <strong>Settings</strong> and the device is
308on a metered network, the system blocks background data usage and signals apps
309to use less data in the foreground wherever possible &mdash; such as by limiting
310bit rate for streaming, reducing image quality, deferring optimistic precaching,
311and so on. Users can whitelist specific apps to allow background metered data
312usage even when Data Saver is turned on.</p>
313
314<p>Android N extends the {@link android.net.ConnectivityManager} to provide apps a
315way to <a href="{@docRoot}preview/features/data-saver.html#status">retrieve the
316user's Data Saver preferences</a> and <a
317href="{@docRoot}preview/features/data-saver.html#monitor-changes">monitor
318preference changes</a>. All apps should check whether the user has enabled Data
319Saver and make an effort to limit foreground and background data usage.</p>
320
321
Andrew Solovay097b1152016-04-06 17:33:00 -0700322<h2 id="vulkan">Vulkan API</h2>
323
324<p>
325 Android N integrates <a href="http://www.khronos.org/vulkan" class=
326 "external-link">Vulkan™</a>, a new 3D rendering API, into the platform. Like
327 <a href="https://www.khronos.org/opengles/" class="external-link">OpenGL™
328 ES</a>, Vulkan is an open standard for 3D graphics and rendering maintained
329 by the Khronos Group.
330</p>
331
332<p>
333 Vulkan is designed from the ground up to minimize CPU overhead in the driver,
334 and allow your application to control GPU operation more directly. Vulkan
335 also enables better parallelization by allowing multiple threads to perform
336 work such as command buffer construction at once.
337</p>
338
339<p>
340 Vulkan development tools and libraries are rolled into the Android NDK. They
341 include:
342</p>
343
344<ul>
345 <li>Headers
346 </li>
347
348 <li>Validation layers (debug libraries)
349 </li>
350
351 <li>SPIR-V shader compiler
352 </li>
353
354 <li>SPIR-V runtime shader compilation library
355 </li>
356</ul>
357
358<p>
359 Vulkan is only available to apps on devices with Vulkan-capable hardware,
David Friedman93970ba2016-05-13 01:23:13 -0700360 such as Nexus 5X, Nexus 6P, and Nexus Player. We're working closely with our
Andrew Solovay097b1152016-04-06 17:33:00 -0700361 partners to bring Vulkan to more devices as soon as possible.
362</p>
363
364<p>
Andrew Solovayf5266e52016-04-12 17:32:57 -0700365 For more information, see the the <a href=
366 "{@docRoot}ndk/guides/graphics/index.html">API documentation</a>.
Andrew Solovay097b1152016-04-06 17:33:00 -0700367</p>
368
Dirk Dougherty59428922016-03-10 18:54:49 -0800369<h2 id="tile_api">Quick Settings Tile API</h2>
370
371
372<div style="float:right;max-width:320px">
373<img src="{@docRoot}preview/images/quicksettings.png" style="padding-left:1.5em;">
374
375<p class="img-caption" style="padding-left:2em;">
376 <strong>Figure 5.</strong> Quick Settings tiles in the notification shade.
377</p>
378
379
380 </div><p>Quick Settings is a popular and simple way to expose key settings and actions,
381directly from the notification shade. In Android N, we've expanded the scope of
382Quick Settings to make it even more useful and convenient. </p>
383
384<p>We've added more room for additional Quick Settings tiles, which users can
385access across a paginated display area by swiping left or right. We've also
386given users control over what Quick Settings tiles appear and where they are
387displayed &mdash; users can add or move tiles just by dragging and dropping them. </p>
388
389<p>For developers, Android N also adds a new API that lets you define your own
390 Quick Settings tiles to give users easy access to key controls and actions in your app.</p>
391
392<p>
393 Quick Settings tiles are reserved for controls or actions that are either
394 urgently required or frequently used, and should not be used as shortcuts to
395 launching an app.
396</p>
397
398<p>
399 Once you’ve defined your tiles, you can surface them to users, who can add
400 them to Quick Settings just by drag and drop.
401</p>
402
403<p>
404 For information about creating an app tile, see the
405 <code>android.service.quicksettings.Tile</code> in the downloadable <a href=
406 "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>.
407</p>
408
409
410
411<h2 id="number-blocking">Number-blocking</h2>
412
413<p>Android N now supports number-blocking in the platform and provides a
414framework API to let service providers maintain a blocked-number list. The
Andrew Solovayef935042016-03-14 14:25:36 -0700415default SMS app, the default phone app, and carrier apps can read from and
Dirk Dougherty59428922016-03-10 18:54:49 -0800416write to the blocked-number list. The list is not accessible to other apps.</p>
417
418<p>By making number-blocking a standard feature of the platform, Android provides
419a consistent way for apps to support number-blocking across a wide range of
420devices. Among the other benefits that apps can take advantage of are:</p>
421
422<ul>
423 <li> Numbers blocked on calls are also blocked on texts
424 <li> Blocked numbers can persist across resets and devices through the Backup &amp;
425Restore feature
426 <li> Multiple apps can use the same blocked numbers list
427</ul>
428
429<p>Additionally, carrier app integration through Android means that carriers can
430read the blocked numbers list on the device and perform service-side blocking
431for the user in order to stop unwanted calls and texts from reaching the user
432through any medium, such as a VOIP endpoint or forwarding phones.</p>
433
434<p>
435 For more information, see <code>android.provider.BlockedNumberContract</code>
436 in the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API
437 Reference</a>.
438</p>
439
440<h2 id="call_screening">Call screening</h2>
441
442<p>
443 Android N allows the default phone app to screen incoming calls. The phone
444 app does this by implementing the new <code>CallScreeningService</code>,
445 which allows the phone app to perform a number of actions based on an
446 incoming call's {@link android.telecom.Call.Details Call.Details}, such as:
447</p>
448
449<ul>
450 <li> Reject the incoming call
451 <li> Do not allow the call to the call log
452 <li> Do not show the user a notification for the call
453</ul>
454
455<p>
456 For more information, see <code>android.telecom.CallScreeningService</code>
457 in the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API
458 Reference</a>.
459</p>
460
461
462<h2 id="multi-locale_languages">Multi-locale support, more languages</h2>
463
464
465<p>Android N now lets users select <strong>multiple locales</strong> in Settings,
466to better support bilingual use-cases. Apps can use
467a new API to get the user's selected locales and then offer more sophisticated
468user experiences for multi-locale users &mdash; such as showing search results in
469multiple languages and not offering to translate webpages in a language the
470user already knows.</p>
471
472<p>Along with multi-locale support, Android N also expands the range of languages
473available to users. It offers more than 25 variants each for commonly used
474languages such as English, Spanish, French, and Arabic. It also adds partial
475support for more than 100 new languages.</p>
476
477<p>Apps can get the list of locales set by the user by calling <code>LocaleList.GetDefault()</code>. To support the expanded number of locales, Android N is changing the way
478that it resolves resources. Make sure that you test and verify that your apps
479working as expected with the new resource resolution logic.</p>
480
481<p>To learn about the new resource-resolution behavior and the best practices you
482should follow, see <a href="{@docRoot}preview/features/multilingual-support.html"
483>Multilingual Support</a>.</p>
484
Eric Schmidt700127a2016-05-12 16:29:18 -0700485
486<h2 id="emoji">New Emojis</h2>
487
488<p>
489 Android N introduces additional emojis and emoji-related features including
490 skin tone emojis and support for variation
491 selectors. If your app supports emojis,
492 follow the guidelines below to take advantage of these emoji-related features.
493</p>
494
495<ul>
496 <li>
497 <strong>Check that a device contains an emoji before inserting it.</strong>
498 To check which emojis are present in the
499 system font, use the {@link android.graphics.Paint#hasGlyph(String)} method.
500 </li>
501 <li>
502 <strong>Check that an emoji supports variation selectors.</strong>
503 Variation selectors allow you to
504 present certain emojis in color or in black-and-white.
505 On mobile devices, apps should represent emojis in color rather than black-and-white. However,
506 if your app displays emojis inline with text, then it should use the black-and-white variation.
507 To determine whether an emoji has a variation, use the variation selector.
508 For a complete list of characters with variations, review the
509 <em>emoji variation sequences</em> section of the
510 <a class="external-link"
511 href="http://www.unicode.org/Public/9.0.0/ucd/StandardizedVariants-9.0.0d1.txt">
512 Unicode documentation on variations</a>.
513 </li>
514 <li>
515 <strong>Check that an emoji supports skin tone.</strong> Android N allows users to modify the
516 rendered skin tone of emojis to their preference. Keyboard apps should provide visual
517 indications for emojis that have multiple skin tones and should allow users to
518 select the skin tone that they prefer. To determine which system emojis have
519 skin tone modifiers, use the {@link android.graphics.Paint#hasGlyph(String)}
520 method. You can determine which emojis use skin tones by reading the
521 <a class="external-link"
522 href="http://unicode.org/emoji/charts/full-emoji-list.html">
523 Unicode documentation</a>.
524 </li>
525</ul>
526
527
Dirk Dougherty59428922016-03-10 18:54:49 -0800528<h2 id="icu4">ICU4J APIs in Android</h2>
529
530<p>
531 Android N now offers a subset of <a href=
532 "http://site.icu-project.org/">ICU4J</a> APIs in the Android framework under
533 the <code>android.icu</code> package. Migration is easy, and mostly entails
534 simply changing from the <code>com.java.icu</code> namespace to
535 <code>android.icu</code>. If you are already using an ICU4J bundle in your
536 apps, switching to the <code>android.icu</code> APIs provided in the Android
537 framework can produce substantial savings in APK size.
538</p>
539
540<p>
541 To learn more about the Android ICU4J APIs, see <a href=
542 "{@docRoot}preview/features/icu4j-framework.html">ICU4J Support</a>.
543</p>
544
545
546
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800547<h2 id="gles_32">OpenGL&trade; ES 3.2 API</h2>
548
549<p>Android N adds framework interfaces and platform support for OpenGL ES 3.2, including:</p>
550
551<ul>
552 <li> All extensions from the <a class="external-link"
553href="https://www.khronos.org/registry/gles/extensions/ANDROID/ANDROID_extension_pack_es31a.txt">Android Extension Pack</a></a> (AEP) except for <code>EXT_texture_sRGB_decode</code>.
554 <li> Floating-point framebuffers for HDR and deferred shading.
555 <li> BaseVertex draw calls to enable better batching and streaming.
556 <li> Robust buffer access control to reduce WebGL overhead.
557</ul>
558
559<p>The framework API for OpenGL ES 3.2 on Android N is provided with the
560<code>GLES32</code> class. When using OpenGL ES 3.2, be sure to declare the
Andrew Solovay9b218572016-03-09 11:17:07 -0800561requirement in your manifest file, using the <code>&lt;uses-feature&gt;</code> tag and
Dirk Doughertycf65e4842016-03-07 22:31:57 -0800562the <code>android:glEsVersion</code> attribute. </p>
563
564<p>For information about using OpenGL ES, including how to check a device's
565supported OpenGL ES version at runtime, see the <a
566href="{@docRoot}guide/topics/graphics/opengl.html">OpenGL ES API guide</a>.</p>
567
568
Dirk Dougherty59428922016-03-10 18:54:49 -0800569<h2 id="android_tv_recording">Android TV recording</h2>
570
571<p>Android N adds the ability to record and playback content from Android TV input
572services via new recording APIs. Building on top of existing time-shifting
573APIs, TV input services can control what channel data can be recorded, how
574recorded sessions are saved, and manage user interaction with recorded content. </p>
575
576<p>For more information, see <a
577href="{@docRoot}preview/features/tv-recording-api.html">Android TV Recording APIs</a>.</p>
578
579
580<h2 id="android_for_work">Android for Work</h2>
581
582<p>Android for Work adds many new features and APIs for devices running Android N.
Kevin Hufnagleb6d17232016-03-22 11:29:03 -0700583Some highlights are below &mdash; for a complete list of changes, see
584<a href="{@docRoot}preview/features/afw.html">Android for Work Updates</a>.</p>
Dirk Dougherty59428922016-03-10 18:54:49 -0800585
586<h3 id="work_profile_security_challenge">Work profile security challenge </h3>
587
588<p>
Andrew Solovay097b1152016-04-06 17:33:00 -0700589 Profile owners targeting the N SDK
590 can specify a separate security challenge for apps running in
Dirk Dougherty59428922016-03-10 18:54:49 -0800591 the work profile. The work challenge is shown when a user attempts to open
592 any work apps. Successful completion of the security challenge unlocks the
593 work profile and decrypts it if necessary. For profile owners,
594 <code>ACTION_SET_NEW_PASSWORD</code> prompts the user to set a work
595 challenge, and <code>ACTION_SET_NEW_PARENT_PROFILE_PASSWORD</code> prompts
596 the user to set a device lock.
597</p>
598
599<p>
Andrew Solovay097b1152016-04-06 17:33:00 -0700600 Profile owners can set distinct passcode policies for the work challenge
Dirk Dougherty59428922016-03-10 18:54:49 -0800601 (such as how long the PIN needs to be, or whether a fingerprint can be used
602 to unlock the profile) using the <code>setPasswordQuality()</code>,
603 <code>setPasswordMinimumLength()</code> and related methods. The profile
604 owner can also set the device lock using the <code>DevicePolicyManager</code>
605 instance returned by the new <code>getParentProfileInstance()</code> method.
606 Additionally, profile owners can customize the credentials screen for the
607 work challenge using the new <code>setOrganizationColor()</code> and
608 <code>setOrganizationName()</code> methods.
609</p>
610<h3 id="turn_off_work">Turn off work </h3>
611
612<p>On a device with a work profile, users can toggle work mode. When work mode is
613off the managed user is temporarily shut down, which disables work profile
614apps, background sync, and notifications. This includes the profile owner
615application. When work mode is off, the system displays a persistent status
616icon to remind the user that they can't launch work apps. The launcher
617indicates that work apps and widgets are not accessible. </p>
618
619<h3 id="always_on_vpn">Always on VPN </h3>
620
621<p>Device owners and profile owners can ensure that work apps always connect
622through a specified VPN. The system automatically starts that VPN after the
623device boots.</p>
624
625<p>
626 New <code>DevicePolicyManager</code> methods are
627 <code>setAlwaysOnVpnPackage()</code> and
628 <code>getAlwaysOnVpnPackage()</code>.
629</p>
630
631<p>Because VPN services can be bound directly by the system without app
632interaction, VPN clients need to handle new entry points for Always on VPN. As
633before, services are indicated to the system by an intent filter matching
634action <code>android.net.VpnService</code>. </p>
635
636<p>
637 Users can also manually set Always on VPN clients that implement
638 <code>VPNService</code> methods in the primary user using
639 <strong>Settings&gt;More&gt;Vpn</strong>.
640</p>
641
Andrew Solovay097b1152016-04-06 17:33:00 -0700642<h3 id="custom_provisioning">Customized provisioning</h3>
643
644<p>
645 An application can customize the profile owner and device owner provisioning
646 flows with corporate colors and logos.
647 <code>DevicePolicyManager.EXTRA_PROVISIONING_MAIN_COLOR</code> customizes
648 flow color. <code>DevicePolicyManager.EXTRA_PROVISIONING_LOGO_URI</code>
649 customizes the flow with a corporate logo.
650</p>
651
Dirk Dougherty59428922016-03-10 18:54:49 -0800652<h2 id="accessibility_enhancements">Accessibility enhancements</h2>
653
654<p>Android N now offers Vision Settings directly on the Welcome screen for new
655device setup. This makes it much easier for users to discover and configure
656accessibility features on their devices, including magnification gesture, font
657size, display size, and TalkBack. </p>
658
659<p>With these accessibility features getting more prominent placement, your users
660are more likely to try your app with them enabled. Make sure you test your apps
661early with these settings enabled. You can enable them from Settings >
662Accessibility.</p>
663
664<p>Also in Android N, accessibility services can now help users with motor
665impairments to touch the screen. The new API allows building services with
666features such as face-tracking, eye-tracking, point scanning, and so on, to
667meet the needs of those users.</p>
668
669<p>For more information, see <code>android.accessibilityservice.GestureDescription</code>
Eric Schmidt57a83b52016-05-10 12:37:38 -0700670 in the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>.</p>
Dirk Dougherty59428922016-03-10 18:54:49 -0800671
672
673<h2 id="direct_boot">Direct boot</h2>
674
675<p>Direct boot improves device startup times and lets registered
676apps have limited functionality even after an unexpected reboot.
677For example, if an encrypted device reboots while the user is sleeping,
David Friedman93970ba2016-05-13 01:23:13 -0700678registered alarms, messages and incoming calls can now continue to notify
Dirk Dougherty59428922016-03-10 18:54:49 -0800679the user as normal. This also means accessibility services can also be
680 available immediately after a restart.</p>
681
682<p>Direct boot takes advantage of file based encryption in Android N
683to enable fine grained encryption policies for both system and app data.
684The system uses a device-encrypted store for select system data and explicitly
685registered app data. By default a credential-encrypted store is used for all
686 other system data, user data, apps, and app data. </p>
687
688<p>At boot, the system starts in a restricted mode with access to
689device-encrypted data only, and without general access to apps or data.
690If you have components that you want to run in this mode, you can register
691them by setting a flag in the manifest. After restart, the system activates
692registered components by broadcasting the <code>LOCKED_BOOT_COMPLETED</code>
693intent. The system ensures registered device-encrypted app data is available
694before unlock. All other data is unavailable until the User confirms their lock
695 screen credentials to decrypt it. </p>
696
697For more information, see <a href="{@docRoot}preview/features/direct-boot.html">Direct Boot</a>.</p>
698</p>
699
700
701<h2 id="key_attestation">Key Attestation</h2>
702
703<p>Hardware-backed keystores provide a much safer method to create, store,
704and use cryptographic keys on Android devices. They protect keys from the
705Linux kernel, potential Android vulnerabilities, and extraction
706from rooted devices.</p>
707
708<p>To make it easier and more secure to use hardware-backed keystores,
709Android N introduces Key Attestation. Apps and off-devices can use Key
710Attestation to strongly determine whether an RSA or EC key pair is
711hardware-backed, what the properties of the key pair are, and what
712 constraints are applied to its usage and validity. </p>
713
714<p>Apps and off-device services can request information about a key pair
715through an X.509 attestation certificate which must be signed by a valid
716attestation key. The attestation key is an ECDSA signing key which is
717injected into the device’s hardware-backed keystore at the factory.
718Therefore, an attestation certificate signed by a valid attestation
719key confirms the existence of a hardware-backed keystore, along with
720 details of key pairs in that keystore.</p>
721
722<p>To ensure that the device is using a secure, official Android factory
723image, Key Attestation requires that the device <a
724class="external-link"
725href="https://source.android.com/security/verifiedboot/verified-boot.html#bootloader_requirements">bootloader</a>
726provide the following information to the <a class="external-link"
727href="https://source.android.com/security/trusty/index.html">Trusted
728Execution Environment (TEE)</a>:</p>
729
730<ul>
731<li>The OS version and patch level installed on the device</li>
732<li>The <a href="https://source.android.com/security/verifiedboot/index.html"
733class="external-link" >Verified Boot</a> public key and lock status</li>
734 </ul>
735
736<p>For more information about the hardware-backed keystore feature,
737see the guide for <a href="https://source.android.com/security/keystore/"
738class="external-link">Hardware-backed Keystore</a>.</p>
739
740<p>In addition to Key Attestation, Android N also introduces
741 fingerprint-bound keys that are not revoked on fingerprint enrollment.</p>
742
743<h2 id="network_security_config">Network Security Config</h2>
744
745<p>In Android N, apps can customize the behavior of their secure (HTTPS, TLS)
746connections safely, without any code modification, by using the declarative
747<em>Network Security Config</em> instead of using the conventional
748error-prone programmatic APIs (e.g. X509TrustManager).</p>
749
750 <p>Supported features:</p>
751<ul>
752<li><b>Custom trust anchors.</b> Lets an application customize which
753Certificate Authorities (CA) are trusted for its secure connections. For
754example, trusting particular self-signed certificates or a restricted set of public CAs.
755</li>
756<li><b>Debug-only overrides.</b> Lets an application developer safely debug
757secure connections of their application without added risk to the installed
758base.
759</li>
760<li><b>Cleartext traffic opt-out.</b> Lets an application protect itself from
761accidental usage of cleartext traffic.</li>
762<li><b>Certificate pinning.</b> An advanced feature that lets an application
763 limit which server keys are trusted for secure connections.</li>
764</ul>
765
766<p>For more information, see <a
767href="{@docRoot}preview/features/security-config.html">Network Security
768Config</a>.</p>
769
770<h2 id="default_trusted_ca">Default Trusted Certificate Authority</h2>
771
772<p>By default, apps that target Android N only trust system-provided certificates
773and no longer trust user-added Certificate Authorities (CA). Apps targeting Android
774N that wish to trust user-added CAs should use the
775<a href="{@docRoot}preview/features/security-config.html">Network Security Config</a> to
776specify how user CAs should be trusted.</p>
777
778<h2 id="apk_signature_v2">APK signature scheme v2</h2>
779
Kevin Hufnagle7cd4a102016-05-04 15:30:45 -0700780<p>
781 Android N introduces APK Signature Scheme v2, a new app-signing scheme that
Kevin Hufnagleaa1b7dd2016-05-11 17:38:45 -0700782 offers faster app install times and more protection against unauthorized
783 alterations to APK files. By default, Android Studio 2.2 and the Android
784 Plugin for Gradle 2.2 sign your app using both APK Signature Scheme v2 and
785 the traditional signing scheme, which uses JAR signing.
Kevin Hufnagle7cd4a102016-05-04 15:30:45 -0700786</p>
Dirk Dougherty59428922016-03-10 18:54:49 -0800787
Kevin Hufnagle7cd4a102016-05-04 15:30:45 -0700788<p>
Kevin Hufnagleaa1b7dd2016-05-11 17:38:45 -0700789 Although we recommend applying APK Signature Scheme v2 to your app, this new
790 scheme is not mandatory. If your app doesn't build properly when using APK
791 Signature Scheme v2, you can disable the new scheme. The disabling process
792 causes Android Studio 2.2 and the Android Plugin for Gradle 2.2 to sign your
793 app using only the traditional signing scheme. To sign with only the
794 traditional scheme, open the module-level <code>build.gradle</code> file, then
795 add the line <code>v2SigningEnabled false</code> to your release signing
796 configuration:
Kevin Hufnagle7cd4a102016-05-04 15:30:45 -0700797</p>
Dirk Dougherty59428922016-03-10 18:54:49 -0800798
Kevin Hufnagle7cd4a102016-05-04 15:30:45 -0700799<pre>
800 android {
801 ...
802 defaultConfig { ... }
803 signingConfigs {
804 release {
805 storeFile file("myreleasekey.keystore")
806 storePassword "password"
807 keyAlias "MyReleaseKey"
808 keyPassword "password"
809 <strong>v2SigningEnabled false</strong>
810 }
811 }
812 }
813</pre>
814
Kevin Hufnagleaa1b7dd2016-05-11 17:38:45 -0700815<p class="caution"><strong>Caution: </strong> If you sign your app using APK
816 Signature Scheme v2 and make further changes to the app, the app's signature
817 is invalidated. For this reason, use tools such as <code>zipalign</code>
818 before signing your app using APK Signature Scheme v2, not after.
819</p>
820
Kevin Hufnagle7cd4a102016-05-04 15:30:45 -0700821<p>
Kevin Hufnagleaa1b7dd2016-05-11 17:38:45 -0700822 For more information, read the Android Studio documents that describe how to
823 <a href="{@docRoot}studio/tools/publishing/app-signing.html#release-mode">
824 sign an app</a> in Android Studio and how to <a href=
Kevin Hufnagle7cd4a102016-05-04 15:30:45 -0700825 "{@docRoot}studio/tools/building/configuring-gradle.html#signing"> configure
Kevin Hufnagleaa1b7dd2016-05-11 17:38:45 -0700826 the build file for signing apps</a> using the Android Plugin for Gradle.
Kevin Hufnagle7cd4a102016-05-04 15:30:45 -0700827</p>
Dirk Dougherty59428922016-03-10 18:54:49 -0800828
829<h2 id="scoped_directory_access">Scoped directory access</h2>
830
831<p>In Android N, apps can use new APIs to request access to specific <a
832href="{@docRoot}guide/topics/data/data-storage.html#filesExternal">external
833storage</a> directories, including directories on removable media such as SD
834cards. The new APIs greatly simplify how your application accesses standard
835external storage directories, such as the <code>Pictures</code> directory. Apps
836like photo apps can use these APIs instead of using
837<code>READ_EXTERNAL_STORAGE</code>, which grants access to all storage
838directories, or the Storage Access Framework, which makes the user navigate to
839the directory.</p>
840
841<p>Additionally, the new APIs simplify the steps a user takes to grant external
842storage access to your app. When you use the new APIs, the system uses a simple
843permissions UI that clearly details what directory the application is
844requesting access to.</p>
845
846<p>For more information, see the
847<a href="{@docRoot}preview/features/scoped-folder-access.html">Scoped
848Directory Access</a> developer documentation.</p>
849
David Friedman93970ba2016-05-13 01:23:13 -0700850<h2 id="keyboard_shortcuts_helper">Keyboard Shortcuts Helper</h2>
851
852<p>
853In Android N, the user can press Meta+/ to trigger a Keyboard Shortcuts
854screen that displays all shortcuts available both from the system and from
855the app in focus. These are retrieved automatically from the app’s menu if
856available, but developers can provide their own fine-tuned shortcuts lists
857for the screen. This is done simply by overriding the following method
858in {@code Activity.java}:
859</p>
860
861<pre>
862public void onProvideKeyboardShortcuts(
863 List<KeyboardShortcutGroup> data, Menu menu, int deviceId)
864</pre>
865
866<p>
867To trigger the Keyboard Shortcuts Helper from anywhere in your app,
868call {@code requestKeyboardShortcutsHelper} for the relevant activity.
869</p>
870
871<h2 id="sustained_performance_api">Sustained Performance API</h2>
872
873<p>
874Performance can fluctuate dramatically for long-running apps, because the
875system throttles system-on-chip engines as device components reach their
876temperature limits. This fluctuation presents a moving target for app
877developers creating high-performance, long-running apps.
878</p>
879
880<p>
881To address these limitations, Android N includes support for
882<em>sustained performance mode</em>, enabling OEMs to provide hints on
883device-performance capabilities for long-running applications. App developers
884can use these hints to tune applications for a predictable,
885consistent level of device performance over long periods of time.
886</p>
887
888<p>
889App developers can try out this new API in the N Developer Preview on
890Nexus 6P devices only. To use this feature,
891set the sustained performance window flag for the window
892you want to run in sustained performance mode. Set this flag using the
893{@code setSustainedPerformanceMode(boolean)} method. The system automatically
894disables this mode when the window is no longer in focus.
895</p>
896
Andrew Solovay097b1152016-04-06 17:33:00 -0700897<h2 id="print_svc">Print Service Enhancements</h2>
898
899<p>
900 In Android N, print service developers can now surface additional information
901 about individual printers and print jobs.
902</p>
903
904<p>
905 When listing individual printers, a print service can now set per-printer
906 icons in two ways:
907</p>
908
909<ul>
910 <li>You can set an icon from a resource ID by calling
911 <code>PrinterInfo.Builder.setResourceIconId()</code>
912 </li>
913
914 <li>You can show an icon from the network by calling
915 <code>PrinterInfo.Builder.setHasCustomPrinterIcon()</code>, and setting a
916 callback for when the icon is requested using
917 <code>android.printservice.PrinterDiscoverySession.onRequestCustomPrinterIcon()</code>
918 </li>
919</ul>
920
921<p>
922 In addition, you can provide a per-printer activity to display additional
923 information by calling <code>PrinterInfo.Builder.setInfoIntent()</code>.
924</p>
925
926<p>
927 You can indicate the progress and status of print jobs in the print job
928 notification by calling
929 <code>android.printservice.PrintJob.setProgress()</code> and
930 <code>android.printservice.PrintJob.setStatus()</code>, respectively.
931</p>
932
933<p>
934 For more information about these methods, see the downloadable <a href=
935 "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>.
936</p>
Eric Schmidt186fada2016-04-27 11:48:22 -0700937
David Friedman93970ba2016-05-13 01:23:13 -0700938<h2 id="framemetrics_api">FrameMetricsListener API</h2>
939
940<p>
941The FrameMetricsListener API allows an app to monitor its UI rendering
942performance by exposing a streaming pubsub API to transfer frame
943timing info for the app's current window. The data returned is
944equivalent to that displayed by {@code adb shell dumpsys gfxinfo framestats},
945but is not limited to the past 120 frames.
946</p>
947
948<p>
949You can use FrameMetricsListener to measure interaction-level UI
950performance in production, without a USB connection. This API
951allows collection of data at a much higher granularity than does
952{@code adb shell dumpsys gfxinfo}. This higher granularity is possible because
953the system can collect data for particular interactions in the app; the system
954need not capture a global summary of the entire app’s
955performance, or clear any global state. You can use this
956capability to gather performance data and catch regressions in UI performance
957for real use cases within an app.
958</p>
959
960<p>
961The API provides a callback interface to be implemented and
962registered on the window that you wish to monitor:
963</p>
964
965<pre>
966 public interface FrameMetricsListener {
967 void onMetricsAvailable(Window window, FrameMetrics frameMetrics,
968 int dropCountSinceLastInvocation);
969 }
970</pre>
971
972<p>
973The API returns a FrameMetrics object, which contains timing data that
974the rendering subsystem reports for various milestones in a frame lifecycle.
975The supported metrics are: {@code UNKNOWN_DELAY_DURATION},
976{@code INPUT_HANDLING_DURATION}, {@code ANIMATION_DURATION},
977{@code LAYOUT_MEASURE_DURATION}, {@code DRAW_DURATION}, {@code SYNC_DURATION},
978{@code COMMAND_ISSUE_DURATION}, {@code SWAP_BUFFERS_DURATION},
979{@code TOTAL_DURATION}, and {@code FIRST_DRAW_FRAME}
980</p>
981
982
Eric Schmidt186fada2016-04-27 11:48:22 -0700983<h2 id="virtual_files">Virtual Files</h2>
984
985<p>
986 In previous versions of Android, your app could use the Storage Access
987 Framework to allow users to select files from their cloud storage accounts,
988 such as Google Drive. However, there was no way to represent files that did
989 not have a direct bytecode representation; every file was required to provide
990 an input stream.
991</p>
992
993<p>
994 Android N adds the concept of <em>virtual files</em> to the Storage Access
995 Framework. The virtual files feature allows your
996 {@link android.provider.DocumentsProvider} to return document URIs that can be
997 used with an {@link android.content.Intent#ACTION_VIEW} intent even if they
998 don't have a direct bytecode representation. Android N also allows you to
999 provide alternate formats for user files, virtual or otherwise.
1000</p>
1001
1002<p>
1003 To get a URI for a virtual document in your app, first you create an
1004 {@link android.content.Intent} to open the file picker UI. Since an app
1005 cannot directly open a virtual file by using the
1006 {@link android.content.ContentResolver#openInputStream(Uri) openInputStream()}
1007 method, your app does not receive any virtual files if you include the
1008 {@link android.content.Intent#CATEGORY_OPENABLE} category.
1009</p>
1010
1011<p>
1012 After the user has made a selection, the system calls the
1013 {@link android.app.Activity#onActivityResult onActivityResult()} method.
1014 Your app can retrieve the URI of the virtual file and get an input stream, as
1015 demonstrated in the code snippet below.
1016</p>
1017
1018<pre>
1019 // Other Activity code ...
1020
1021 final static private int REQUEST_CODE = 64;
1022
1023 // We listen to the OnActivityResult event to respond to the user's selection.
1024 &#64;Override
1025 public void onActivityResult(int requestCode, int resultCode,
1026 Intent resultData) {
1027 try {
1028 if (requestCode == REQUEST_CODE &amp;&amp;
1029 resultCode == Activity.RESULT_OK) {
1030
1031 Uri uri = null;
1032
1033 if (resultData != null) {
1034 uri = resultData.getData();
1035
1036 ContentResolver resolver = getContentResolver();
1037
1038 // Before attempting to coerce a file into a MIME type,
1039 // check to see what alternative MIME types are available to
1040 // coerce this file into.
1041 String[] streamTypes =
1042 resolver.getStreamTypes(uri, "*/*");
1043
1044 AssetFileDescriptor descriptor =
1045 resolver.openTypedAssetFileDescriptor(
1046 uri,
1047 streamTypes[0],
1048 null);
1049
1050 // Retrieve a stream to the virtual file.
1051 InputStream inputStream = descriptor.createInputStream();
1052 }
1053 }
1054 } catch (Exception ex) {
1055 Log.e("EXCEPTION", "ERROR: ", ex);
1056 }
1057 }
1058</pre>
1059
1060<p>
1061 For more information about accessing user files, see the
1062 <a href="{@docRoot}guide/topics/providers/document-provider.html">Storage
1063 Access Frameworks guide</a>.
Eric Schmidt12317682016-05-10 08:40:53 -07001064</p>