blob: b207e35d22d5f5c0f9defb829075ed4db337e5c3 [file] [log] [blame]
Joe Fernandez306f1ce2015-05-01 12:51:21 -07001page.title=API Overview
Joe Fernandeze7866882015-05-06 17:15:03 -07002page.keywords=preview,sdk,compatibility
Joe Fernandeza06ac3a2015-05-15 15:42:17 -07003sdk.platform.apiLevel=23
Joe Fernandez306f1ce2015-05-01 12:51:21 -07004@jd:body
5
6
7<div id="qv-wrapper">
8<div id="qv">
9
10<h2>In this document
11 <a href="#" onclick="hideNestedItems('#toc44',this);return false;" class="header-toggle">
12 <span class="more">show more</span>
13 <span class="less" style="display:none">show less</span></a></h2>
14
15<ol id="toc44" class="hide-nested">
Joe Fernandeza06ac3a2015-05-15 15:42:17 -070016 <li><a href="#backup">Auto Backup for Apps</a></li>
17 <li><a href="#notifications">Notifications</a></li>
18 <li><a href="#authentication">Authentication</a>
19 <ul>
20 <li><a href="#fingerprint-authentication">Fingerprint Authentication</a></li>
21 <li><a href="#confirm-credentials">Confirm Credentials</a></li>
22 </ul>
Joe Fernandez306f1ce2015-05-01 12:51:21 -070023 </li>
Joe Fernandeza06ac3a2015-05-15 15:42:17 -070024 <li><a href="#direct-share">Direct Share</a></li>
25 <li><a href="#voice-interactions">Voice Interactions</a></li>
26 <li><a href="#bluetooth-stylus">Bluetooth Stylus Support</a></li>
27 <li><a href="#audio">New Audio Features</a></li>
28 <li><a href="#afw">New Android for Work Features</a></li>
29</ol>
30
31<h2>API Differences</h2>
32<ol>
33<li><a href="">API level 22 to M &raquo;</a> </li>
Joe Fernandez306f1ce2015-05-01 12:51:21 -070034</ol>
35
36</div>
37</div>
38
39<p>The M Developer Preview gives you an advance look at the upcoming release
40for the Android platform, which offers new features for users and app
41developers. This document provides an introduction to the most notable APIs.</p>
42
43<p>The M Developer Preview is intended for <strong>developer early
44adopters</strong> and <strong>testers</strong>. If you are interested in
45influencing the direction of the Android framework,
46<a href="{@docRoot}preview/setup-sdk.html">give the M Developer Preview a
47try</a> and send us your feedback!</p>
48
49<p class="caution"><strong>Caution:</strong> Do not not publish apps
50that use the M Developer Preview to the Google Play store.</p>
51
52<p class="note"><strong>Note:</strong> This document often refers to classes and
53methods that do not yet have reference material available on <a
54href="{@docRoot}">developer.android.com</a>. These API elements are
55formatted in {@code code style} in this document (without hyperlinks). For the
56preliminary API documentation for these elements, download the <a
Joe Fernandeza06ac3a2015-05-15 15:42:17 -070057href="http://storage.googleapis.com/androiddevelopers/preview/m-developer-preview-reference.zip">
58preview reference</a>.</p>
Joe Fernandez306f1ce2015-05-01 12:51:21 -070059
Joe Fernandeza06ac3a2015-05-15 15:42:17 -070060<h3>Important behavior changes</h3>
Joe Fernandez306f1ce2015-05-01 12:51:21 -070061
Joe Fernandeza06ac3a2015-05-15 15:42:17 -070062<p>If you have previously published an app for Android, be aware that your app might be affected
63by changes in M.</p>
Joe Fernandez306f1ce2015-05-01 12:51:21 -070064
Joe Fernandeza06ac3a2015-05-15 15:42:17 -070065<p>Please see <a href="api-changes.html">Behavior Changes</a> for complete information.</p>
Joe Fernandez306f1ce2015-05-01 12:51:21 -070066
Joe Fernandeza06ac3a2015-05-15 15:42:17 -070067<h2 id="backup">Auto Backup for Apps</h2>
68<p>The system now performs automatic full data backup and restore for apps. This behavior is
69enabled by default for apps targeting M; you do not need to add any additional code. If users
70delete their Google account, their backup data is deleted as well.</p>
71<p>To learn how this feature works and how to configure what to back up on the file system,
72see the <a href="">App Backup for Apps guide</a>.</p>
73
74<h2 id="notifications">Notifications</h2>
75<p>M adds the following API changes for notifications:</p>
76<ul>
77 <li>New {@code NotificationListenerService.INTERRUPTION_FILTER_ALARMS} filter level that
78 corresponds to the new <em>Alarms only</em> do not disturb mode.</li>
79 <li>New {@code Notification.CATEGORY_REMINDER} category value that is used to distinguish
80 user-scheduled reminders from other events
81 ({@link android.app.Notification#CATEGORY_EVENT}) and alarms
82 ({@link android.app.Notification#CATEGORY_ALARM}).</li>
83 <li>New {@code android.graphics.drawable.Icon} class which can be attached to your notifications
84 via the Notification.Builder.setIcon() and Notification.Builder.setLargeIcon() methods.</li>
85 <li>New {@code NotificationManager.getActiveNotifications()} method that allows your apps to
86 find out which of their notifications are currently alive.</li>
87</ul>
88
89<h2 id="authentication">Authentication</h2>
90<p>The M release offers new APIs to let you authenticate users by using their fingerprint scans on
91supported devices, and check how recently the user was last authenticated using a device unlocking
92mechanism (such as a lockscreen password). Use these APIs in conjunction with
93the <a href="{@docRoot}training/articles/keystore.html">Android Keystore system</a>.</p>
94
95<h3 id="fingerprint-authentication">Fingerprint Authentication</h3>
96
97<p>To authenticate users via fingerprint scan, get an instance of the new
98{@code android.hardware.fingerprint.FingerprintManager} class and call the
99{@code FingerprintManager.authenticate()} method. Your app must be running on a device with a
100fingerprint sensor. You must implement the user interface for the fingerprint
101authentication flow on your app, and use the standard fingerprint Android icon in your UI.
102If you are developing multiple apps that use fingerprint authentication, note that each app must
103authenticate the user’s fingerprint independently.
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700104</p>
105
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700106<img src="{@docRoot}preview/images/fingerprint-screen_2x.png"
107srcset="{@docRoot}preview/images/fingerprint-screen.png 1x, preview/images/fingerprint-screen_2x.png 2x"
108style="margin:0 0 10px 20px" width="282" height="476" />
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700109
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700110<p>To use this feature in your app, first add the {@code USE_FINGERPRINT} permission in your
111manifest.</p>
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700112
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700113<pre>
114&lt;uses-permission
115 android:name="android.permission.USE_FINGERPRINT" /&gt;
116</pre>
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700117
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700118<p>The following snippet shows how you might listen for fingerprint events in your
119{@code FingerprintManager.AuthenticationCallback} implementation.</p>
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700120
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700121<pre>
122// Call this to start listening for fingerprint events
123public void startListening(FingerprintManager.CryptoObject cryptoObject) {
124 if (!isFingerprintAuthAvailable()) {
125 return;
126 }
127 mCancellationSignal = new CancellationSignal();
128 mSelfCancelled = false;
129 mFingerprintManager.authenticate(cryptoObject,
130 mCancellationSignal, this, 0 /* flags */);
131 // Icon to display when prompting users to start a fingerprint scan
132 mIcon.setImageResource(R.drawable.ic_fp_40px);
133}
134
135// Helper method to check if the device supports fingerprint
136// scanning and if the user has enrolled at least one fingerprint.
137public boolean isFingerprintAuthAvailable() {
138 return mFingerprintManager.isHardwareDetected()
139 &amp;&amp; mFingerprintManager.hasEnrolledFingerprints();
140}
141</pre>
142
143<h3 id="confirm-credentials">Confirm Credentials</h3>
144<p>Your app can authenticate users based on how recently they last unlocked their device. You can
145use the same public or secret key to authenticate users into multiple apps. This feature frees
146users from having to remember additional app-specific passwords, and avoids the need for you to
147implement your own authentication user interface.</p>
148
149<p>You can set your own authentication policy by setting constraints against the key that you are
150generating or importing. To set the constraints for using a key, use the
151{@code android.security.KeyPairGeneratorSpec.Builder} and
152{@code android.security.KeyGeneratorSpec.Builder} classes for public key pairs and secret keys
153respectively. If you are importing keys, use the {@link android.security.KeyStoreParameter.Builder}
154class to set your constraints.</p>
155
156<p>The following example shows how you might create a symmetric key in the Keystore which can only be
157used if the user has successfully unlocked the device within the last 5 minutes.</p>
158
159<pre>
160private void createKey() {
161 // Generate a key to decrypt payment credentials, tokens, etc.
162 // This will most likely be a registration step for the user when
163 // they are setting up your app.
164 try {
165 KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
166 ks.load(null);
167 KeyGenerator keyGenerator = KeyGenerator.getInstance("AES",
168 "AndroidKeyStore");
169 keyGenerator.init(new KeyGeneratorSpec.Builder(this)
170 // Alias of the entry in Android KeyStore where the key will appear
171 .setAlias(KEY_NAME)
172 // Key use constraints
173 .setPurposes(KeyStoreKeyProperties.Purpose.ENCRYPT
174 | KeyStoreKeyProperties.Purpose.DECRYPT)
175 .setBlockModes("CBC")
176 .setUserAuthenticationRequired(true)
177 // Require that the user has unlocked in the last 5 minutes
178 .setUserAuthenticationValidityDurationSeconds(5 * 60)
179 .setEncryptionPaddings("PKCS7Padding")
180 .build());
181 keyGenerator.generateKey();
182 } catch (NoSuchAlgorithmException | NoSuchProviderException
183 | InvalidAlgorithmParameterException | KeyStoreException
184 | CertificateException | IOException e) {
185 throw new RuntimeException(e);
186 }
187}
188</pre>
189
190<p>To determine the last time users logged into their account, call the
191{@code android.accounts.AccountManager.confirmCredentials()} method. If the call is successful, the
192method returns an bundle that includes a {@code KEY_LAST_AUTHENTICATED_TIME} value which indicates
193the last time, in milliseconds, that the credential for that account was validated or created.</p>
194
195<h2 id="direct-share">Direct Share</h2>
196
197<img src="{@docRoot}preview/images/direct-share-screen_2x.png"
198srcset="{@docRoot}preview/images/direct-share-screen.png 1x, preview/images/direct-share-screen_2x.png 2x"
199style="float:right; margin:0 0 20px 30px" width="312" height="385" />
200
201<p>This release provides you with APIs to makes sharing intuitive and quick for users. You can now
202define <em>deep links</em> that target a specific activity in your app. These deep links are
203exposed to users via the <em>Share</em> menu. This feature allows users to share content to
204targets, such as contacts, within other apps. For example, the deep link might launch an
205activity in another social network app, which lets the user share content directly to a specific
206friend or community in that app.</p>
207
208<p>To enable sharing via deep links, you must define a class that extends the
209{@code android.service.} <br>
210{@code chooser.ChooserTargetService} class. Declare your
211{@code ChooserTargetService} in the manifest. Within that declaration, specify the
212{@code BIND_CHOOSER_TARGET_SERVICE} permission and an intent filter with the
213{@code SERVICE_INTERFACE} action.</p>
214<p>The following example shows how you might declare the {@code ChooserTargetService} in your
215manifest.</p>
216<br>
217<br>
218<br>
219<pre>
220&lt;service android:name=".ChooserTargetService"
221 android:label="&#64;string/service_name"
222 android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE"&gt;
223 &lt;intent-filter&gt;
224 &lt;action android:name="android.service.chooser.ChooserTargetService" /&gt;
225 &lt;/intent-filter&gt;
226&lt;/service&gt;
227</pre>
228
229<p>For each activity that you want to expose to the {@code ChooserTargetService}, add a
230{@code &lt;meta-data&gt;} element with the name
231{@code "android.service.chooser.chooser_target_service"} in your app manifest.
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700232</p>
233
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700234<pre>
235&lt;activity android:name=".MyShareActivity”
236 android:label="&#64;string/share_activity_label"&gt;
237 &lt;intent-filter>
238 &lt;action android:name="android.intent.action.SEND" /&gt;
239 &lt;/intent-filter>
240&lt;meta-data
241 android:name="android.service.chooser.chooser_target_service"
242 android:value=".ChooserTargetService" /&gt;
243&lt;/activity>
244</pre>
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700245
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700246<h2 id="voice-interactions">Voice Interactions</h2>
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700247<p>
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700248This release provides a new voice interaction API which, together with
249<a href="https://developers.google.com/voice-actions/" class="external-link">Voice Actions</a>,
250allows you to build conversational voice experiences into your apps. Call the
251{@code android.app.Activity.isVoiceInteraction()} method to determine if your activity was
252started in response to a voice action. If so, your app can use the
253{@code android.app.VoiceInteractor} class to request a voice confirmation from the user, select
254from a list of options, and more.</p>
255<p>To learn more about implementing voice actions, see the voice interaction API
256<a href="https://developers.google.com/voice-actions/interaction/"
257class="external-link">guide</a>.
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700258</p>
259
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700260<h2 id="bluetooth-stylus">Bluetooth Stylus Support</h2>
261<p>The M release provides improved support for user input using a Bluetooth stylus. If the user
262touches a stylus with a button on the screen of your app, the
263{@link android.view.MotionEvent#getToolType(int) getTooltype()} method now returns
264{@code TOOL_TYPE_STYLUS}. The {@link android.view.MotionEvent#getButtonState() getButtonState()}
265method returns {@link android.view.MotionEvent#BUTTON_SECONDARY} when the user
266presses the primary stylus button. If the stylus has a second button, the same method returns
267{@link android.view.MotionEvent#BUTTON_TERTIARY} when the user presses it. If the user presses
268both buttons simultaneously, the method returns both these values. In addition, the system reports
269the user button-press action to the new {@code View.onStylusButtonPressListener} and
270{@code GestureDetector.OnStylusButtonPressListener} callbacks in your activity, if you have
271registered these listeners in your app.</p>
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700272
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700273<h2 id="audio">New Audio Features</h2>
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700274
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700275<p>This release adds enhancements to audio processing on Android, including: </p>
276<ul>
277 <li>Support for the <a href="http://en.wikipedia.org/wiki/MIDI" class="external-link">MIDI</a>
278protocol, with the new {@code android.media.midi} APIs. Use these APIs to send and receive MIDI
279events.</li>
280 <li>New {@code android.media.AudioRecord.Builder} and {@code android.media.AudioTrack.Builder}
281classes to create digital audio capture and playback objects respectively, and configure audio
282source and sink properties to override the system defaults.</li>
283 <li>API hooks for associating audio and input devices. This is particularly useful if your app
284allows users to start a voice search from a game controller or remote control connected to Android
285TV. The system invokes the new {@code android.app.Activity.onSearchRequested()} callback when the
286user starts a search. To determine if the user's input device has a built-in microphone, retrieve
287the {@link android.view.InputDevice} object from that callback, then call the new
288{@code InputDevice.hasMic()} method.</li>
289 <li>New {@code android.media.AudioDevicesManager} class which lets you retrieve a list of all
290attached source and sink audio devices. You can also specify an
291{@code android.media.OnAudioDeviceConnectionListener} object if you want your app to be notified
292when an audio device is connected or disconnected.</li>
293</ul>
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700294
Joe Fernandeza06ac3a2015-05-15 15:42:17 -0700295<h2 id="afw">New Android for Work Features</h2>
296<p>This release includes the following new APIs for Android for Work:</p>
297<ul>
298 <li><strong>Enhanced controls for Corporate-Owned, Single-Use devices:</strong> The Device Owner
299can now control the following settings to improve management of
300Corporate-Owned, Single-Use (COSU) devices:
301 <ul>
302 <li>Disable or re-enable the keyguard with the
303{@code DevicePolicyManager.setKeyguardEnabledState()} method.</li>
304 <li>Disable or re-enable the status bar (including quick settings, notifications, and the
305navigation swipe-up gesture that launches Google Now) with the
306{@code DevicePolicyManager.setStatusBarEnabledState()} method.</li>
307 <li>Disable or re-enable safe boot with the {@link android.os.UserManager} constant
308{@code DISALLOW_SAFE_BOOT}.</li>
309 <li>Prevent the screen from turning off while plugged in with the
310 {@link android.provider.Settings.Global} constant {@code STAY_ON_WHILE_PLUGGED_IN}.</li>
311 </ul>
312 </li>
313 <li><strong>Silent install and uninstall of apps by Device Owner:</strong> A Device Owner can now
314silently install and uninstall applications using the {@link android.content.pm.PackageInstaller}
315APIs, independent of Google Play for Work. You can now provision devices through a Device Owner that
316fetches and installs apps without user interaction. This feature is useful for enabling one-touch
317provisioning of kiosks or other such devices without activating a Google account.</li>
318<li><strong>Silent enterprise certificate access: </strong> When an app calls
319{@link android.security.KeyChain#choosePrivateKeyAlias(android.app.Activity,android.security.KeyChainAliasCallback,java.lang.String[],java.security.Principal[],java.lang.String,int,java.lang.String) choosePrivateKeyAlias()},
320prior to the user being prompted to select a certificate, the Profile or Device Owner can now call
321the {@code DeviceAdminReceiver.onChoosePrivateKeyAlias()} method to provide the alias silently to
322the requesting application. This feature lets you grant managed apps access to certificates
323without user interaction.</li>
324<li><strong>Auto-acceptance of system updates.</strong> By setting a system update policy with
325{@code DevicePolicyManager.setSystemUpdatePolicy()}, a Device Owner can now auto-accept a system
326update, for instance in the case of a kiosk device, or postpone the update and prevent it being
327taken by the user for up to 30 days. Furthermore, an administrator can set a time window in which an
328update must be taken, for example during the hours when a kiosk device is not in use. When a
329system update is available, the system checks if the Work Policy Controller app has set a system
330update policy, and behaves accordingly.
331</li>
332<li>
333<strong>Delegated certificate installation.</strong> A Profile or Device Owner can now grant a
334third-party app the ability to call these {@link android.app.admin.DevicePolicyManager} certificate
335management APIs:
336<ul>
337 <li>{@link android.app.admin.DevicePolicyManager#getInstalledCaCerts(android.content.ComponentName)
338getInstalledCaCerts()}</li>
339 <li>{@link android.app.admin.DevicePolicyManager#hasCaCertInstalled(android.content.ComponentName,byte[])
340hasCaCertInstalled()}</li>
341 <li>{@link android.app.admin.DevicePolicyManager#installCaCert(android.content.ComponentName,byte[])
342installCaCert()}</li>
343 <li>{@link android.app.admin.DevicePolicyManager#uninstallCaCert(android.content.ComponentName,byte[])
344uninstallCaCert()}</li>
345 <li>{@link android.app.admin.DevicePolicyManager#uninstallAllUserCaCerts(android.content.ComponentName)
346uninstallAllUserCaCerts()}</li>
347 <li>{@link android.app.admin.DevicePolicyManager#installKeyPair(android.content.ComponentName,java.security.PrivateKey,java.security.cert.Certificate,java.lang.String)
348installKeyPair()}</li>
349</ul>
350</li>
351<li><strong>Enterprise factory reset protection.</strong> When provisioning a Device Owner, you can
352now configure parameters for bypassing Factory Reset Protection (FRP), by setting the
353{@code DeviceManagerPolicy.EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS} bundle. An NFC Programmer
354app can provide these parameters after a device has been reset to bypass FRP and provision the device,
355without requiring the previously configured Google account. If you don't modify these parameters,
356FRP remains in-place and prevents the device from being activated without the previously activated
357Google credentials.</li>
358<li><strong>Data usage tracking.</strong> A Profile or Device Owner can now query for the data
359usage statistics visible in <em>Settings > Data</em> usage by using the new
360{@code android.app.usage.NetworkStatsManager} methods. Profile Owners are automatically granted
361permission to query data on the profile they manage, while Device Owners get access to usage data
362of the managed primary user.</li>
363</ul>
Joe Fernandez306f1ce2015-05-01 12:51:21 -0700364
365<p class="note">
366 For a detailed view of all API changes in the M Developer Preview, see the <a href=
367 "{@docRoot}preview/reference.html">API Differences Report</a>.
368</p>