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