Earlier this year Google unveiled its new version of Android — code named Android M — and like with Android Lollipop, we also got a developer preview. The Android M developer preview gave developers a clear timeline to test their apps, and an opportunity to explore the new features the latest version of Android has to offer. We now know this version of Android as Android 6.0 Marshmallow. Google has also finalized the Android version 23 APIs, and developers can download the official Android 6.0 SDK via the SDK Manager in Android Studio.
With Android Marshmallow, Google has made some improvements over previous versions of the OS and added a number of new features to the Android platform; from the new permission system to the assist APIs, Marshmallow is turning out to be a worthy successor to last year’s Lollipop. We looked through the Android 23 APIs and their documentation to find noteworthy features and their APIs. Here are some of our favorites so far:
Android for Work
With Android Marshmallow, developers now have more tools than ever to build applications for corporate and enterprise environments. Boasting a number of enhancements, the
DevicePolicyManager class now incorporates methods such as
setKeyguardDisabled() and setStatusBarDisabled(), which allow significant improvements in the use of corporate-owned, single-use (COSU) devices. Third-party applications can also call a number of DevicePolicyManager methods, allowing more flexibility in COSU app design. System updates can now be automatically accepted or postponed by setting a system update policy with
DevicePolicyManager.setSystemUpdatePolicy(). Developers can also now disable/re-enable safe boot, and prevent plugged in devices’ screen from turning off, enabling a more singular and focused experience for corporate-oriented applications.
Another new feature is the ability to define direct share targets that launch a specific activity in your app. These APIs help make sharing quick and intuitive for users. Using the Share menu, users can directly share content to targets within other apps. To enable direct share targets, you must define a class that extends the android.service.chooser.ChooserTargetService class, and declare your
ChooserTargetService in the manifest. Within that declaration, specify the
BIND_CHOOSER_TARGET_SERVICE permission and an intent filter with the
One of the most exciting features announced during this year’s Google I/O was “Google Now on Tap,” where by long-pressing on the home button, you get a contextual pop-up card from Google Now related to whatever is currently on the screen. By default, the context is determined from the Android text fields and view hierarchy, but by using the Assist API, developers can add more information to the default context. You’ll have to implement the
Application.OnProvideAssistDataListener interface. Register this listener by using
registerOnProvideAssistDataListener(). In order to provide activity-specific contextual information, override the
onProvideAssistData() callback and optionally, the new
Activity.onProvideAssistContent() callback. Also, if you’d rather not have the contents of your screen shared with the assistant, you can create a
WindowManager.LayoutParams with the
FLAG_SECURE, and set the param on your view of interest using the
WindowsManager system service.
Note that, the available APIs exist since API 18.
Android Marshmallow brings official support of fingerprint authentication to the Android platform. To use this feature in your app, you will first need to add the
USE_FINGERPRINT permission in your manifest. To authenticate users via fingerprint, scan using a device with a compatible fingerprint sensor, get an instance of the new
android.hardware.fingerprint.FingerprintManager class and call the
FingerprintManager.authenticate() method. You must also implement the user interface for the fingerprint authentication on your app, and use the standard Android fingerprint icon in your UI. This is to provide a uniform experience across the Android platform.
Take a look at video posted at: Fingerprint and payments APIs.
Nothing major is coming to the notifications API this time around, but the Android notifications are getting a few upgrades. For one, there’s a new
NotificationListenerService.INTERRUPTION_FILTER_ALARMS filter level that corresponds to the new Alarms only do not disturb mode. There is also a new
Notification.CATEGORY_REMINDER category value that is used to distinguish user-scheduled reminders from other events (
CATEGORY_EVENT) and alarms (
CATEGORY_ALARM). Also coming to Android Marshmallow is a new
android.graphics.drawable.Icon class which can be attached to your notifications via the
Notification.Builder.setLargeIcon() methods. Finally, there’s a new
NotificationManager.getActiveNotifications() method that allows your apps to find out which of their notifications are currently alive.
Bluetooth Stylus Support
Google has included improved support for Bluetooth styluses. Apps are now able to listen for stylus button presses and perform secondary actions by registering the new
GestureDetector.onContextClickListener callbacks in their activities. The
MotionEvent methods and constants can be used to detect stylus button interactions:
If the user touches a stylus with a button on the screen of your app, the
getTooltype() method returns
Bluetooth Low Energy Scanning
With low power Bluetooth Beacons getting increasingly popular, it makes a lot of sense that Android would evolve to better utilize the location context that they provide. The new
android.bluetooth.le.ScanSettings.Builder.setCallbackType() ensures that your app is only notified when an advertisement packet matching the set
ScanFilter is first found, and when it is not seen for a period of time. This approach to scanning is more power-efficient than what’s provided in the previous platform version.
Note that, while you can targeting API level 18 and above for BLE app, you should consider about battery life and effeciency while using deprecated APIs with BLE scanning.
Android Marshmallow offers a number of upgrades to the existing video processing APIs. The new
android.media.MediaSync class helps applications synchronously render audio and video streams. The audio buffers are submitted asynchronously and are returned via a callback to avoid blocking the main UI thread. It also supports dynamic playback rate. Android Marshmallow also adds the new
MediaDrm.EVENT_SESSION_RECLAIMED event, which indicates that a session opened by the app has been reclaimed by the resource manager.
There have been a few incremental enhancements to audio processing in the new APIs, particularly focusing on support for the MIDI protocol with the new
android.media.midi classes. Developers can now use these APIs to send and receive MIDI events. Android also adds new classes to create digital audio capture and playback objects. The
AudioManager.getDevices() method lets you retrieve a list of all audio devices currently connected to the system. By registering an
android.media.AudioDeviceCallback object, you can receive a callback when an audio device is connected or disconnected.
The Camera2 API now supports both YUV and private opaque format image re-processing. Developers can decide if these reprocessing capabilities are available by calling the
CameraManager.getCameraCharacteristics() method and checking for the
REPROCESS_MAX_CAPTURE_STALL key. If a device supports reprocessing, you can create a reprocessable camera capture session by calling
CameraDevice.createReprocessableCaptureSession(), and create requests for input buffer reprocessing. The ImageReader class now supports
android.graphics.ImageFormat.PRIVATE format image streams, allowing apps to maintain a circular image queue of
ImageReader output images, choose one or more images, and send them to the
ImageWriter for camera reprocessing.
Just like its predecessor Lollipop, Google has created a number of tools for developers to use to make great apps with Android Marshmallow. The latest version of Android is shaping up to provide an even better Android experience for both existing and new users. The Android M developer preview has given us a good idea of what we will be seeing in the near future, and we can’t wait for the release of the first official Android Marshmallow device system images later this year.