page.title=Behavior Changes page.keywords=preview,sdk,compatibility sdk.platform.apiLevel=23 @jd:body
API Level: M
Along with new features and capabilities, the M Developer Preview includes a variety of system changes and API behavior changes. This document highlights some of the key changes that you should be understand and account for in your apps.
If you have previously published an app for Android, be aware that your app might be affected by these changes in the platform.
This preview introduces a new runtime permissions model, where users can now directly manage their app permissions at runtime. This model gives users improved visibility and control over permissions, while streamlining the installation and auto-update processes for app developers. Users can set permissions on or off for all apps running on the M Preview. However, apps that don’t target the M Preview cannot request permissions at runtime.
On your apps that target the M Preview, make sure to check and request for permissions at runtime. To determine if your app has been granted a permission, call the new {@code Context.checkSelfPermission()} method. To request for a permission, call the new {@code Activity.requestPermission()} method.
For more information on supporting the new permissions model in your app, see Android M Preview Runtime Permissions.
This preview introduces new power-saving optimizations for idle devices and apps.
If a device is unplugged and left stationary with the screen off for a period of time, it goes into Doze mode where it attempts to keep the system in a sleep state. In this mode, devices periodically resume normal operations for brief periods of time so that app syncing can occur and the system can perform any pending operations.
The following restrictions apply to your apps while in Doze mode:
When the device exists doze mode, it executes any jobs and syncs that are pending.
You can test this feature by connecting a device running the M Preview to your development machine and calling the following commands:
$ adb shell dumpsys battery unplug $ adb shell dumpsys deviceidle step $ adb shell dumpsys deviceidle -h
Note: The upcmoning Google Cloud Messaging release lets you designate high-priority messages. If your app receives high-priority GCM messages, it’s granted brief network access even when the device is in doze mode.
With this preview, the system may determine that apps are idle when they are not in active use. Your app is considered idle after a period of time, unless the system detects any of these signals:
If the device is unplugged, apps deemed idle will have their network access disabled and their syncs and jobs suspended. When the device is plugged into a power supply, these apps are allowed network access and can execute any jobs and syncs that are pending. If the device is idle for long periods of time, idle apps are allowed network access around once a day.
You can test this feature by connecting a device running the M Preview to your development machine and calling the following commands:
$ adb shell am broadcast -a android.os.action.DISCHARGING $ adb shell am set-idle <packageName> true $ adb shell am set-idle <packageName> false $ adb shell am get-idle <packageName>
Note: The upcoming Google Cloud Messaging (GCM) release lets you designate high-priority messages. If your app receives high-priority GCM messages, it’s granted brief network access even when the app is idle.
With this preview, users can adopt external storage devices such as SD cards. Adopting an external storage device encrypts and formats the device to behave like internal storage. This feature allows users to move both apps and private data of those apps between storage devices. When moving apps, the system respects the {@code android:installLocation} preference in the manifest.
If your app accesses the following APIs or fields, be aware that the file paths they return will dynamically change when the app is moved between internal and external storage devices. When building file paths, it is strongly recommended that you always call these APIs dynamically. Don’t use hardcoded file paths or persist fully-qualified file paths that were built previously.
To debug this feature in the developer preview, you can enable adoption of a USB drive that is connected to an Android device through a USB On-The-Go (OTG) cable, by running this command:
$ adb shell sm set-force-adoptable true
This preview removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the {@link java.net.HttpURLConnection} class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your {@code build.gradle} file:
android { useLibrary 'org.apache.http.legacy' }
Android is moving away from OpenSSL to the BoringSSL library. If you’re using the Android NDK in your app, don't link against cryptographic libraries that are not a part of the NDK API, such as {@code libcrypto.so} and {@code libssl.so}. These libraries are not public APIs, and may change or break without notice across releases and devices. In addition, you may expose yourself to security vulnerabilities. Instead, modify your native code to call the Java cryptography APIs via JNI or to statically link against a cryptography library of your choice.
Setting the volume directly or muting specific streams via the {@link android.media.AudioManager} class is no longer supported. The {@link android.media.AudioManager#setStreamSolo(int,boolean) setStreamSolo()} method is deprecated, and you should call the {@code AudioManager.requestAudioFocus()} method instead. Similarly, the {@link android.media.AudioManager#setStreamMute(int,boolean) setStreamMute()} method is deprecated; instead, call the {@code AudioManager.adjustStreamVolume()} method and pass in the direction value {@code ADJUST_MUTE} or {@code ADJUST_UNMUTE}.
When users select text in your app, you can now display text selection actions such as Cut, Copy, and Paste in a floating toolbar. The user interaction implementation is similar to that for the contextual action bar, as described in Enabling the contextual action mode for individual views.
To implement a floating toolbar for text selection, make the following changes in your existing apps:
If you are using Android Support Library revision 22.2, be aware that floating toolbars are not backward-compatible and appcompat takes control over {@link android.view.ActionMode} objects by default. This prevents floating toolbars from being displayed. To enable {@link android.view.ActionMode} support in an {@link android.support.v7.app.AppCompatActivity}, call {@code android.support.v7.app.AppCompatActivity.getDelegate()}, then call {@code android.support.v7.app.AppCompatDelegate.setHandleNativeActionModesEnabled()} on the returned {@link android.support.v7.app.AppCompatDelegate} object and set the input parameter to {@code false}. This call returns control of {@link android.view.ActionMode} objects to the framework. In devices running the M Preview, that allows the framework to support {@link android.support.v7.app.ActionBar} or floating toolbar modes, while on pre-M Preview devices, only the {@link android.support.v7.app.ActionBar} modes are supported.
With this preview, the Android Keystore provider no longer supports DSA. ECDSA is still supported.
Keys which do not require encryption at rest will no longer be deleted when secure lock screen is disabled or reset (for example, by the user or a Device Administrator). Keys which require encryption at rest will be deleted during these events.
Support for the {@code -night} resource qualifier has been updated. Previously, night mode was only available when a device was docked and in car mode. With this preview, night mode is available on all devices and is user-configurable via Settings > Display > Theme. You can adjust this setting globally using {@link android.app.UiModeManager#setNightMode(int) setNightMode()}. The Dark theme corresponds to {@link android.app.UiModeManager#MODE_NIGHT_YES}. When the device is in night mode, the resource framework prefers resources that have the {@code -night} qualifier. To take advantage of user-configurable Dark mode in your app, extend from the {@code Theme.Material.DayNight} set of themes rather than {@code Theme.Material} or {@code Theme.Material.Light}.
This preview introduces the following behavior changes to the Wi-Fi and networking APIs.
In this preview, the model for accessing shared resources in the camera service has been changed from the previous “first come, first serve” access model to an access model where high-priority processes are favored. Changes to the service behavior include:
The ART runtime now properly implements access rules for the {@link java.lang.reflect.Constructor#newInstance(java.lang.Object...) newInstance()} method. This change fixes a problem where Dalvik was checking access rules incorrectly in previous versions. If your app uses the {@link java.lang.reflect.Constructor#newInstance(java.lang.Object...) newInstance()} method and you want to override access checks, call the {@link java.lang.reflect.Constructor#setAccessible(boolean) setAccessible()} method with the input parameter set to {@code true}. If your app uses the v7 appcompat library or the v7 recyclerview library, you must update your app to use to the latest versions of these libraries. Otherwise, make sure that any custom classes referenced from XML are updated so that their class constructors are accessible.
This preview updates the behavior of the dynamic linker. The dynamic linker now understands the difference between a library’s {@code soname} and its path ( public bug 6670), and search by {@code soname} is now implemented. Apps which previously worked that have bad {@code DT_NEEDED} entries (usually absolute paths on the build machine’s file system) may fail when loaded.
The {@code dlopen(3) RTLD_LOCAL} flag is now correctly implemented. Note that {@code RTLD_LOCAL} is the default, so calls to {@code dlopen(3)} that didn’t explicitly use {@code RTLD_LOCAL} will be affected (unless your app explicitly used {@code RTLD_GLOBAL}). With {@code RTLD_LOCAL}, symbols will not be made available to libraries loaded by later calls to {@code dlopen(3)} (as opposed to being referenced by {@code DT_NEEDED} entries).
The platform now performs stricter validation of APKs. An APK is considered corrupt if a file is declared in the manifest but not present in the APK itself. An APK must be re-signed if any of the contents are removed.
This preview includes the following behavior changes for Android for Work: