Skip to main content

Android O

Android O Features and APIs


Android O introduces a variety of new features and capabilities for users and developers. This document highlights what's new for developers.
Make sure to check out Android O Behavior Changes to learn about areas where platform changes may affect your apps.

Notifications


In Android O, we've redesigned notifications to provide an easier and more consistent way to manage notification behavior and settings. These changes include:
  • Notification channels: Android O introduces notification channels that allow you to create a user-customizable channel for each type of notification you want to display. The user interface refers to notification channels as notification categories. To learn how to implement notification channels, see the Notification Channels guide.
  • Snoozing: Users can snooze notifications to reappear at a later time. Notifications reappear with the same level of importance they first appeared with. Apps can remove or update a snoozed notification, but updating a snoozed notification does not cause it to reappear.
  • Notification timeouts: You can now set a timeout when creating a notification usingNotification.Builder.setTimeout(). You can use this method to specify a duration after which a notification should be cancelled. If required, you can cancel a notification before the specified timeout duration elapses.
  • Notification dismissal: The system now distinguishes whether a notification is dismissed by a user, or removed by an app. To check how notifications are dismissed, you should implement the newonNotificationRemoved() method of the NotificationListenerService class.
  • Background colors: You can now set and enable a background color for a notification. You should only use this feature in notifications for ongoing tasks which are critical for a user to see at a glance. For example, you could set a background color for notifications related to driving directions, or a phone call in progress. You can also set the desired background color using Notification.Builder.setColor(). Doing so allows you to use Notification.Builder.setColorized() to enable the use of a background color for a notification.
  • Messaging style: Notifications that use the MessagingStyle class now display more content in their collapsed form. You should use the MessagingStyle class for notifications that are messaging-related. You can also use the new addHistoricMessage() method to provide context to a conversation by adding historic messages to messaging related notifications.
A notification in Android O.
Inline controls for a notification in Android O.
Figure 1. The screen on the right shows inline controls for notifications in Android O.

Autofill Framework


Account creation, login, and credit card transactions take time and are prone to errors. Users can easily get frustrated with apps that require these types of repetitive tasks.
Android O makes filling out forms, such as login and credit card forms, easier with the introduction of the Autofill Framework. Existing and new apps work with Autofill Framework after the user opts in to autofill.
You can take some steps to optimize how your app works with the framework. For more information, see Autofill Framework Overview.

Picture-in-Picture mode


Android O allows activities to launch in picture-in-picture (PIP) mode. PIP is a special type of multi-window mode mostly used for video playback. PIP mode is already available for Android TV; Android O makes the feature available on other Android devices.
When an activity is in PIP mode, it is in the paused state, but should continue showing content. For this reason, you should make sure your app does not pause playback in its onPause() handler. Instead, you should pause video in onStop(), and resume playback in onStart(). For more information, seeMulti-Window Lifecycle.
To specify that your activity can use PIP mode, set android:supportsPictureInPicture to true in the manifest. (Beginning with Android O, you do not need to set android:resizeableActivity to true if you are supporting PIP mode, either on Android TV or on other Android devices; you only need to setandroid:resizeableActivity if your activity supports other multi-window modes.)

API changes

Android O introduces a new object, PictureInPictureArgs, which you pass to PIP methods to specify how an activity should behave when it is in PIP mode. This object specifies properties such as the activity's preferred aspect ratio.
The existing PIP methods described in Adding Picture-in-picture can now be used on all Android devices, not just on Android TV. In addition, Android O provides the following methods to support PIP mode:
  • Activity.enterPictureInPictureMode(PictureInPictureArgs args): Places the activity in picture-in-picture mode. The activity's aspect ratio and other configuration settings are specified by args. If any fields in args are empty, the system uses the values set the last time you called Activity.setPictureInPictureArgs().
    The specified activity is placed in a corner of the screen; the rest of the screen is filled with the previous activity that was on screen. The activity entering PIP mode goes into the paused state, but remains started. If the user taps the PIP activity, the system shows a menu for the user to interact with; no touch events reach the activity while it is in the PIP state.
  • Activity.setPictureInPictureArgs() Updates an activity's PIP configuration settings. If the activity is currently in PIP mode, the settings are updated; this is useful if activity's aspect ratio changes. If the activity is not in PIP mode, these configuration settings are used regardless of theenterPictureInPictureMode() method that you call.

Working with fonts


Android O introduces a new feature, Fonts in XML, which lets you use fonts as resources. This means, there is no need to bundle fonts as assets. Fonts are compiled in R file and are automatically available in the system as a resource. You can then access these fonts with the help of a new resource type, font. Android O also provides a mechanism to retrieve information related to system fonts and provide file descriptors. For more information, about using fonts as resources and retrieving system fonts, see Working with fonts.

Adaptive icons


Android O introduces adaptive launcher icons. Adaptive icons support visual effects, and can display a variety of shapes across different device models. To learn how to create adaptive icons, see the Adaptive Icons preview feature guide.

Color management


Android developers of imaging apps can now take advantage of new devices that have a wide-gamut color capable display. To display wide gamut images, apps will need to enable a flag in their manifest (per activity) and load bitmaps with an embedded wide color profile (AdobeRGB, Pro Photo RGB, DCI-P3, etc.).

Wi-Fi Aware


Android O adds support for Wi-Fi Aware, which is based on the Neighbor Awareness Networking (NAN) specification. On devices with the appropriate Wi-Fi Aware hardware, apps and nearby devices can discover and communicate over Wi-Fi without an Internet access point. We're working with our hardware partners to bring Wi-Fi Aware technology to devices as soon as possible. For information on how to integrate Wi-Fi Aware into your app, see Wi-Fi Aware.

Companion device pairing


Android O provides APIs that allow you to customize the pairing request dialog when trying to pair with companion devices over Bluetooth, BLE, and Wi-Fi. For more information, see Companion Device Pairing.
For more information about using Bluetooth on Android, see the Bluetooth guide. For changes to Bluetooth that are specific to Android O, see theBluetooth section of the Android O Behavior Changes page.

WebView APIs


Android O provides several APIs to help you manage the WebView objects that display web content in your app. These APIs, which improve your app's stability and security, include the following:
  • Version API
  • Google SafeBrowsing API
  • Termination Handle API
  • Renderer Importance API
To learn more about how to use these APIs, see Managing WebViews.

Pinning shortcuts and widgets


Android O introduces in-app pinning of shortcuts and widgets. In your app, you can create pinned shortcuts and widgets for supported launchers, subject to user permission.
For more information, see the Pinning Shortcuts and Widgets preview feature guide.

Accessibility


Android O supports the following accessibility features for developers who create their own accessibility services:
Language detection
To identify the languages that the Text-to-Speech (TTS) tool has identified within a range of text, use detectLanguages(). This method appears in the TextClassificationManager class, which has been introduced in Android O. You can use the resulting list of TextLanguage objects to identify which areas of text have been assigned to a particular language as well as how confidently TTS has assigned a language to a particular subset of text.
Accessibility button
Your service can request that an accessibility button appear within the system's navigation area by setting theFLAG_REQUEST_ACCESSIBILITY_BUTTON flag within the android:accessibilityFlags attribute. This button offers users a quick way to activate your service's functionality from any screen on the device. Your service can register button interaction callbacks usingregisterAccessibilityButtonCallback().
Note: This feature is available only on devices that provide a software-rendered navigation area. Use the isAccessibilityButtonAvailable()method and the onAvailabilityChanged() callback to keep track of the accessibility button's availability. Ensure that users of your service have alternate ways to access related functionality in cases where the accessibility button is unavailable.
Fingerprint gestures
Your accessibility service can also respond to an alternative input mechanism, directional swipes (up, down, left, and right) along a device's fingerprint sensor. To receive callbacks about these interactions, complete the following sequence of steps:
  1. Declare the USE_FINGERPRINT permission and the CAPABILITY_CAN_CAPTURE_FINGERPRINT_GESTURES capability.
  2. Set the FLAG_CAPTURE_FINGERPRINT_GESTURES flag within the android:accessibilityFlags attribute.
  3. Register for callbacks using registerFingerprintGestureCallback().
Keep in mind that not all devices include fingerprint sensors. You can use the isHardwareDetected() method to identify whether a device supports the sensor. Even on devices that include a fingerprint sensor, your service can use the sensor only when it's not in use for authentication purposes. To identify when the sensor is available, call the isGestureDetectionAvailable() method and implement theonGestureDetectionAvailabilityChanged() callback.
Word-level highlighting
To determine the locations of visible characters in a TextView object, you can pass in EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY as the first argument into refreshWithExtraData(). A Bundle object, which you provide as the second argument to refreshWithExtraData(), is then updated to include a parcelable array of Rect objects. Each Rect object represents the bounding box of a particular character.
If your service uses a TextToSpeech object to dictate the content that appears on-screen, you can obtain more precise timing information about when text-to-speech engines begin speaking individual synthesized words, as long as the text-to-speech engine provides this information. When an engine expects to begin playing audio for a specific range of text, the text-to-speech API notifies your service that speech for the range of text is beginning using the onUtteranceRangeStart() callback.
If you create your own implementation of TextToSpeechService, you can support this new functionality by using the rangeStart() method.
Hint text
Your service can access the hint text of an EditText object using the getHintText() method within the AccessibilityNodeInfo class. Even if a particular EditText object isn't currently displaying hint text, the getHintText() method still provides hint text for your service.
Continued gesture dispatch
Your service can now specify sequences of strokes that belong to the same programmatic gesture by using the final argument, isContinued, in the GestureDescription.StrokeDescription constructor.
To learn more about how to make your app more accessible, see Accessibility.

Permissions


Android O introduces a new permission, android.permission.ANSWER_PHONE_CALLS, which allows apps to answer incoming phone calls programmatically. This permission is classified as dangerous and is part of the PHONE permission group.
To handle an incoming phone call in your app, you can use the acceptRingingCall() method in the TelecomManager class.

Content provider paging


We've updated content providers to include support for loading a large dataset one page at a time. For example, a photo app with many thousands of images can query for a subset of the data to present in a page. Each page of results returned by a content provider is represented by a single Cursor object. Both a client and a provider must implement paging to make use of this feature.
For detailed information about the changes to content providers, see ContentProvider and ContentProviderClient.

Media enhancements


Media metrics

A new getMetrics() method returns a Bundle object containing configuration and performance information, expressed as a map of attributes and values. The getMetrics() method is defined for these media classes:
  • MediaPlayer.getMetrics()
  • MediaRecorder.getMetrics()
  • MediaCodec.getMetrics()
  • MediaExtractor.getMetrics()
Metrics are collected separately for each instance and persist for the lifetime of the instance. If no metrics are available the method returns null. The actual metrics returned depend on the class.

MediaPlayer

Android O adds several new methods to the MediaPlayer class. These methods can improve your app's handling of media playback in several ways:
  • The ability to improve performance by controlling buffering behavior.
  • Fine-grained control when seeking to a frame.
  • The ability to playback DRM-protected material.

MediaRecorder

  • MediaRecorder now supports the MPEG2_TS format which is useful for streaming:
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_2_TS);
    see MediaRecorder.OutputFormat
  • The MediaMuxer can now handle any number of audio and video streams. You are no longer limited to one audio track and/or one video track. Use addTrack() to mix as many tracks as you like.
  • The MediaMuxer can also add one or more metadata tracks containing user-defined per-frame information. The format of the metadata is defined by your application. The metadata track is only supported for MP4 containers.
Metadata can be useful for offline processing. For example, gyro signals from the sensor could be used to perform video stabilization.
When adding a metadata track, the track's mime format must start with the prefix "application/". Writing metadata is the same as writing video/audio data except that the data does not come from a MediaCodec. Instead, the app passes a ByteBuffer with an associated timestamp to thewriteSampleData() method. The timestamp must be in the same time base as the video and audio tracks.
The generated MP4 file uses the TextMetaDataSampleEntry defined in section 12.3.3.2 of the ISOBMFF to signal the metadata's mime format. When using MediaExtractor to extract the file with metadata track, the mime format of the metadata will be extracted into MediaFormat.

Multi-display support


Beginning with Android O, the platform offers enhanced support for multiple displays. If an activity supports multi-window mode and is running on a device with multiple displays, users can move the activity from one display to another. When an app launches an activity, the app can specify which display the activity should run on.
Note: If an activity supports multi-window mode, Android O automatically enables multi-display support for that activity. You should test your app to make sure it works adequately in a multi-display environment.
Only one activity at a time can be in the resumed state, even if the app has multiple displays. The activity with focus is in the resumed state; all other visible activities are paused, but not stopped. For more information on the activity lifecycle when several activities are visible, see Multi-Window Lifecycle.
When a user moves an activity from one display to another, the system resizes the activity and issues runtime changes as necessary. Your activity can handle the configuration change itself, or it can allow the system to destroy the process containing your activity and recreate it with the new dimensions. For more information, see Handling Configuration Changes.

API changes

ActivityOptions provides two new methods to support multiple displays:
setLaunchDisplayId()
Specifies which display the activity should be shown on when it is launched.
getLaunchDisplayId()
Returns the activity's current launch display.

Tool updates

The adb shell is extended to support multiple displays. The shell startcommand can now be used to launch an activity, and to specify the activity's target display:
adb shell start <activity_name> --display <display_id>

New account access and discovery APIs


Android O introduces several improvements to how apps get access to user accounts. For the accounts that they manage, authenticators can use their own policy to decide whether to hide accounts from, or reveal accounts to, an app. The Android system tracks applications which can access a particular account.
In previous versions of Android, apps that wanted to track the list of user accounts had to get updates about all accounts, including accounts with unrelated types. Android O adds the addOnAccountsUpdatedListener(android.accounts.OnAccountsUpdateListener, android.os.Handler, boolean, java.lang.String[]) method, which lets apps specify a list of account types for which account changes should be received.

API changes

AccountManager provides six new methods to help authenticators manage which apps can see an account:
  • setAccountVisibility(android.accounts.Account, java.lang.String, int): Sets the level of visibility for a specific user account and package combination.
  • getAccountVisibility(android.accounts.Account, java.lang.String): Gets the level of visibility for a specific user account and package combination.
  • getAccountsAndVisibilityForPackage(java.lang.String, java.lang.String): Allows authenticators to get the accounts and levels of visibility for a given package.
  • getPackagesAndVisibilityForAccount(android.accounts.Account): Allows authenticators to get stored visibility values for a given account.
  • addAccountExplicitly(android.accounts.Account, java.lang.String, android.os.Bundle, java.util.Map<java.lang.String, java.lang.Integer>): Allows authenticators to initialize the visibility values of an account.
  • addOnAccountsUpdatedListener(android.accounts.OnAccountsUpdateListener, android.os.Handler, boolean, java.lang.String[]): Adds an OnAccountsUpdateListener listener to the AccountManager object. The system calls this listener whenever the list of accounts on the device changes.
Android O introduces two special Package Name values to specify visibility levels for applications which were not set using thesetAccountVisibility(android.accounts.Account, java.lang.String, int) method. The PACKAGE_NAME_KEY_LEGACY_VISIBLE visibility value is applied to apps that have the GET_ACCOUNTS permission, and target versions of Android lower than Android O, or whose signatures match the authenticator targeting any Android version. PACKAGE_NAME_KEY_LEGACY_NOT_VISIBLE provides a default visibility value for apps which were not set previously and for which PACKAGE_NAME_KEY_LEGACY_VISIBLE is not applicable.
For more information about the new account access and discovery APIs, see the reference for AccountManager and OnAccountsUpdateListener.

AnimatorSet


Starting in Android O, the AnimatorSet API now supports seeking and playing in reverse. Seeking lets you set the position of the animation set to a specific point in time. Playing in reverse is useful if your app includes animations for actions that can be undone. Instead of defining two separate animation sets, you can play the same one in reverse.

Autosizing TextView


Android O lets you set the size of your text expand or contract automatically based on the size of the TextView. This means, it is much easier to optimize the text size on different screens or with dynamic content. For more information, about autosizing TextView in Android O, see Autosizing TextView.

Smart sharing


Android O learns about users' personalized sharing preferences and better understands for each type of content which are the right apps to share with. For example, if a user takes a photo of a receipt, Android O suggests an expense-tracking app; if the user takes a selfie, a social media app can better handle the photo. Android O automatically learns all these patterns according to users' personalized preferences.
To enable Smart sharing, add an ArrayList of up to three string annotations to the intent that shares the photo. The annotations should describe the major components or topics of the photo. The following code example shows how to add annotations to the intent:
ArrayList<String> annotations = new ArrayList<>();

annotations.add("topic1");
annotations.add("topic2");
annotations.add("topic3");

intent.putStringArrayListExtra(
    Intent.EXTRA_CONTENT_ANNOTATIONS,
    annotations);
For detailed information about Smart sharing annotations, see EXTRA_CONTENT_ANNOTATIONS.

App categories


Android O allows each app to declare a category that they fit into, when relevant. These categories are used to cluster together apps of similar purpose or function when presenting them to users, such as in Data Usage, Battery Usage, or Storage Usage. You can define a category for your app by setting the android:appCategory attribute in your <application> manifest tag.

New StrictMode detectors


Android O adds three new StrictMode detectors to help identify potential bugs in your app:
  • detectUnbufferedIo() will detect when your app reads or writes data without buffering, which can drastically impact performance.
  • detectContentUriWithoutPermission() will detect when your app accidentally forgets to grant permissions to another app when starting an Activity outside your app.
  • detectUntaggedSockets() will detect when your app performs network traffic without using setThreadStatsTag(int) to tag your traffic for debugging purposes.

Cached data


Android O gives better guidance and behaviors around cached data. Each app is now given a disk space quota for cached data, as returned bygetCacheQuotaBytes(File).
When the system needs to free up disk space, it will start by deleting cached files from apps that are the most over their allocated quota. Thus, if you keep your cached data under your allocated quota, your cached files will be some of the last on the system to be cleared when necessary. When the system is deciding what cached files to delete inside your app, it will consider the oldest files first (as determined by modified time).
There are also two new behaviors that you can enable on a per-directory basis to control how the system frees up your cached data:
  • setCacheBehaviorAtomic(File, boolean) can be used to indicate that a directory and all of its contents should be deleted as a single atomic unit.
  • setCacheBehaviorTombstone(File, boolean) can be used to indicate that instead of deleting files inside a directory, they should be truncated to be 0 bytes in length, leaving the empty file intact.
Finally, when you need to allocate disk space for large files, consider using the new allocateBytes(File, long, int) API, which will automatically clear cached files belonging to other apps (as needed) to meet your request. When deciding if the device has enough disk space to hold your new data, call getAllocatableBytes(File, int) instead of using getUsableSpace(), since the former will consider any cached data that the system is willing to clear on your behalf.

Improved media file access


The Storage Access Framework (SAF) allows apps to expose a custom DocumentsProvider, which can provide access to files in a data source to other apps. In fact, a documents provider can even provide access to files that reside on network storage or that use a protocol like Media Transfer Protocol (MTP).
However, accessing large media files from a remote data source introduces some challenges. Media players require seekable access to a file from a documents provider. In cases where a large media file resides on a remote data source, the documents provider must fetch all of the data in advance and create a snapshot file descriptor. The media player cannot play the file without the file descriptor, thus playback cannot begin until the documents provider finishes downloading the file.
Starting in Android O, the Storage Access Framework allows custom documents providers to create seekable file descriptors for files residing in a remote data source. The SAF can open a file to get a native seekable file descriptor. The SAF then delivers discrete bytes requests to the documents provider. This feature allows a documents provider to return the exact range of bytes that a media player app has requested instead of caching the entire file in advance.
To use this feature, you need to call the new StorageManager.openProxyFileDescriptor() method. The openProxyFileDescriptor() method accepts a ProxyFileDescriptorCallback object as a callback. The SAF invokes the callback any time a client application performs file operations on the file descriptor returned from the documents provider.

Android in the enterprise


Android enterprise introduces many new features and APIs for devices running Android O. We've made the profile owner and device owner management modes more powerful, productive, and easier to provision than ever before. We've also enabled a whole new deployment scenario.
Some notable highlights include the following:
  • The ability to use a managed profile on a corporate-owned device.
  • An overhauled work profile featuring a user-friendly setup flow that drastically reduces setup time.
  • Enterprise management for file-based encryption.
  • Delegation of app management APIs.
To learn more about the new APIs and features for Android enterprise in Android O, see the Android in the Enterprise page.

Java programming language updates


In Android O we are adding OpenJDK Java language features to Android. We are adding java.time from OpenJDK 8 as well as java.nio.file and java.lang.invoke including MethodHandle from OpenJDK 7. Check out the new packages in the API diff report.

Comments

  1. I feel happy to find your post, excellent way of writing and also I would like to share with my colleagues so that they also get the opportunity to read such an informative blog.
    Android Course in Chennai
    Android Training Chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

BLE Pairing vs Bonding

BLE pairing vs. bonding Just a quick write up on the difference between pairing and bonding, since these terms get used interchangeably. I think this has to do with the usage of ‘pairing’ in Bluetooth Classic, or BR/EDR. As far as Bluetooth LE is concerned, pairing and bonding are two very distinct things. The short explanations are that pairing is the exchange of security features each device has, and creating temporary encryption. Bonding is the exchange of long term keys AFTER PAIRING HAS OCCURRED, and STORING THOSE KEYS FOR LATER USE. Pairing is not the creation of permanent security between devices, that  is called bonding. Pairing is the mechanism that allows bonding to occur. Pairing Pairing is the exchange of security features. This includes things like i/o capabilities, requirement for man-in-the-middle protection, etc. The client side begins this exchange. The client essentially says ‘hey, i’d like it if you had these features’. The server replies,...

The One Thing Nobody Has Told You About The Samsung Galaxy S8

The Samsung Galaxy S8 is about the first smartphone to feature Bluetooth 5, the latest standard of the wireless transmission technology. The Sony Xperia Z Premium will also have it, but it’s not due for a while yet. So what, you say? Well, it’s pretty neat and has plenty of new features, such as being twice as fast as the previous version, four times the range range (1000 feet) and more, providing you have devices capable of making the most of it. This has allowed Samsung to come up with something it calls Bluetooth Dual Audio, specified by Samsung on its website but hardly reported. And Bluetooth Dual Audio is even cooler. If you have memories of sharing earbuds with someone special so you can both listen to the same track, those memories are probably warm and rosy, tempered only by the lack of stereo available to both parties. So how much better would it be if you could both connect your own Bluetooth headphones to the same phone at the same time and stream the music to...