10 Things You Should Know About Android P

Gokul Balakrishnan
7 min readMar 10, 2018

--

Android P introduces great new features and capabilities for users and developers. The new version came with about 13 new features in new android P operating system. This shows 10 Things You Should Know About Android P.

Indoor Positioning with Wi-Fi RTT

Android P adds platform support for the IEEE 802.11mc Wi-Fi protocol — also known as Wi-Fi Round-Trip-Time (RTT) — to let you take advantage of indoor positioning in your apps.

On Android P devices with hardware support, your apps can use the new RTT APIs to measure the distance to nearby RTT-capable Wi-Fi Access Points (APs). The device must have location enabled and Wi-Fi scanning turned on (under Settings > Location), and your app must have the ACCESS_FINE_LOCATIONpermission. The device doesn’t need to connect to the APs to use RTT. To maintain privacy, only the phone is able to determine the distance to the AP; the APs do not have this information.

If your device measures the distance to 3 or more APs, you can use a multilateration algorithm to estimate the device position that best fits those measurements. The result is typically accurate within 1 to 2 meters

Display cutout support

Android P offers support for the latest edge-to-edge screens with display cutout for camera and speaker. The new DisplayCutout class lets you find out the location and shape of the non-functional areas where content shouldn’t be displayed. To determine the existence and placement of these cutout areas, use the getDisplayCutout() method.

A new window layout attribute,layoutInDisplayCutoutMode, allows your app to lay out its content around a device’s cutouts. You can set this attribute to one of the following values:

  • LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
  • LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
  • LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER

Android P introduces several enhancements to notifications, all of which are available to developers targeting Android P and above.

Multi-camera support and camera updates

You can now access streams simultaneously from two or more physical cameras on devices running Android P. On devices with either dual-front or dual-back cameras, you can create innovative features not possible with just a single camera, such as seamless zoom, bokeh, and stereo vision. The API also lets you call a logical or fused camera stream that automatically switches between two or more cameras.

Other improvements in camera include new Session parameters that help to reduce delays during initial capture and Surface sharing that lets camera clients handle various use-cases without the need to stop and start camera streaming. We’ve also added APIs for display-based flash support and access to OIS timestamps for app-level image stabilization and special effects.

Android P also enables support for external USB/UVC cameras on supported devices.

Notifications

Android P introduces several enhancements to notifications, all of which are available to developers targeting Android P and above.

Enhanced messaging experience

Starting in Android 7.0 (API level 24), you can add an action to reply to messages or enter other text directly from a notification. Android P enhances this feature with the following enhancements:

  • Support for images: Android P now displays images in Messaging Notifications on phones. You can use setData() on the message to display an image.
  • Simplified support for conversation participants: The new Notification.Person class is used to identify people involved in a conversation, including their avatars and URIs. Many other APIs, such as addMessage(), now leverage the Person class instead of aCharSequence.
  • Save replies as drafts: Your app can retrieve the EXTRA_REMOTE_INPUT_DRAFT sent by the system when a user inadvertently closes a messaging notification. You can use this extra to pre-populate text fields in the app so users can finish their reply.
  • Identify if a conversation is a group conversation: You can use setGroupConversation()to purposefully identify a conversation as a group or non-group conversation.
  • Set the semantic action for an intent: The setSemanticAction() method allows you to give semantic meaning to an action, such as mark as read, delete, reply, and so on.
  • SmartReply: Android P supports the same suggested replies available in your messaging app. Use RemoteInput.setChoices() to provide an array of standard responses to the user.

Channel settings, broadcasts, and Do Not Disturb

Android O introduced Notification Channels allowing you to create a user-customizable channel for each type of notification you want to display. Android P simplifies notification channel settings with these changes:

  • Blocking channel groups: Users can now block entire groups of channels within the notification settings for an app. You can use the isBlocked() method to identify when a group is blocked and, as a result, not send any notifications for channels in that group.Additionally, your app can query for current channel group settings using the newgetNotificationChannelGroup() method.
  • New broadcast intent types: The Android system now sends broadcast intents when the blocking state of notification channels and channel groups’ changes. The app that owns the blocked channel or group can listen for these intents and react accordingly. For further information on these intent actions and extras, refer to the updated constants list in theNotificationManager reference. For information on reacting to broadcast intents, refer toBroadcasts.
  • New Do Not Disturb priority categories: NotificationManager.Policy has two new policy constants: PRIORITY_CATEGORY_ALARMS (alarms are prioritized) andPRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER (media, system, and game sounds are prioritized).

Multi-camera support and camera updates

You can now access streams simultaneously from two or more physical cameras on devices running Android P. On devices with either dual-front or dual-back cameras, you can create innovative features not possible with just a single camera, such as seamless zoom, bokeh, and stereo vision. The API also lets you call a logical or fused camera stream that automatically switches between two or more cameras.

Other improvements in camera include new Session parameters that help to reduce delays during initial capture and Surface sharing that lets camera clients handle various use-cases without the need to stop and start camera streaming. We’ve also added APIs for display-based flash support and access to OIS timestamps for app-level image stabilization and special effects.

ImageDecoder for bitmaps and drawables

Android P introduces ImageDecoder to provide a modernized approach for decoding images. You should use ImageDecoder to decode an image rather than the BitmapFactory andBitmapFactory.Options APIs.

ImageDecoder lets you create a Drawable or aBitmap from a byte buffer, a file, or a URI. To decode an image, first call createSource() with the source of the encoded image. Then, call decodeBitmap() ordecodeDrawable() by passing the ImageDecoder.Source object to create a Bitmap or aDrawable. To change default settings, pass OnHeaderDecodedListener to decodeBitmap() ordecodeDrawable(). ImageDecoder calls onHeaderDecoded() with the image’s default width and height, once they are known. If the encoded image is an animated GIF or WebP, decodeDrawable()returns a Drawable that is an instance of the AnimatedImageDrawable class.

There are different methods you can use to set image properties. These include:

  • To scale the decoded image to an exact size, call setResize() with the target dimensions. You can also scale images using a sample size. Pass the sample size directly to setResize(), or call getSampledSize() to find out what ImageDecoder can sample most efficiently.
  • To crop an image within the range of the scaled image, call setCrop().
  • To create a mutable Bitmap, call setMutable(true).

ImageDecoder also lets you add customized and complicated effects to an image such as rounded corners or circle masks. Use setPostProcessor()with an instance of the PostProcessor class to execute whatever drawing commands you want. When you post-process an AnimatedImageDrawable, effects are applied to all frames.

Animation

Android P introduces a new AnimatedImageDrawableclass for drawing and displaying GIF and WebP animated images. AnimatedImageDrawable works similarly to AnimatedVectorDrawable in that RenderThread drives the animations of AnimatedImageDrawable. RenderThread also uses a worker thread to decode, so that decoding does not interfere with RenderThread. This implementation allows your app to have an animated image without managing its updates or interfering with your app’s UI thread.

An AnimagedImageDrawable can be decoded with the new ImageDecoder. The following code snippet shows how to use ImageDecoder to decode yourAnimatedImageDrawable:

HDR VP9 Video, HEIF image compression, and Media APIs

Android P adds built-in support for High Dynamic Range (HDR) VP9 Profile 2, so you can now deliver HDR-enabled movies to your users from YouTube, Play Movies, and other sources on HDR-capable devices.

Android P adds support for HEIF (heic) images encoding to the platform. HEIF still image samples are supported in the MediaMuxer and MediaExtractorclasses HEIF improves compression to save on storage and network data. With platform support on Android P devices, it’s easy to send and utilize HEIF images from your backend server. Once you’ve made sure that your app is compatible with this data format for sharing and display, give HEIF a try as an image storage format in your app. You can do a jpeg-to-heic conversion using ImageDecoder or BitmapFactory to obtain a bitmap from jpeg, and you can use HeifWriterin the new Support Library alpha to write HEIF still images from YUV byte buffer, Surface, or Bitmap.

Android P also introduces MediaPlayer2. This player supports playlists that are built using DataSourceDesc. To create an instance of MediaPlayer2 use MediaPlayer2.create().

Media metrics are now also available from the AudioTrack, AudioRecord, and MediaDrm classes.

Android P adds new methods to the MediaDRM class to get metrics, HDCP levels, security levels and number of sessions, and to add more control over security levels and secure stops. See the API Diff report for details.

Data cost sensitivity in JobScheduler

With Android P, JobScheduler has been improved to let it better handle network-related jobs for the user, in coordination with network status signals provided separately by carriers.

Jobs can now declare their estimated data size, signal prefetching, and specify detailed network requirements — carriers can report networks as being congested or unmetered. JobScheduler then manages work according to the network status. For example, when a network is congested, JobSchedulermight defer large network requests. When on an unmetered network, JobScheduler can run prefetch jobs to improve the user experience, such as by prefetching headlines.

Neural Networks API 1.1

The Neural Networks API was introduced in Android 8.1 (API level 27)to accelerate on-device machine learning on Android. Android P expands and improving the API, adding support for nine new ops — Pad, BatchToSpaceND, SpaceToBatchND, Transpose, Strided Slice, Mean, Div, Sub, and Squeeze.

Autofill framework

Android 8.0 (API level 26) introduced the autofill framework, which makes it easier to fill out forms in apps. Android P introduces multiple improvements that autofill services can implement to further enhance the user experience when filling out forms. For more details, see the Autofill Framework page.

Security enhancements

Android P introduces a number of new security features, including a unified fingerprint authentication dialog and high-assurance user confirmation of sensitive transactions. For more details, see theSecurity Updates page.

Client-side encryption of Android backups

Android P enables encryption of Android backups with a client-side secret. Because of this privacy measure, the device’s PIN, pattern, or password is required to restore data from the backups made by the user’s device.

Originally published at thoughtnerds.com on March 10, 2018.

--

--

Gokul Balakrishnan

Experienced Android Developer with a demonstrated history of working in the information technology and services industry. Skilled in Java,Kotlin,C#