Android 14 (Source: https://android-developers.googleblog.com/2023/04/android-14-beta-1.html)

Android 14 — What’s New? | Part 1

Kartik Arora
ProAndroidDev
Published in
4 min readApr 18, 2023

--

As a developer, keeping up with the latest changes in Android is essential to building robust and up-to-date mobile apps. Android 14, the latest iteration of the Android operating system, is packed with new features and improvements that can enhance the user experience and streamline the development process.

This article is the first in the “Android 14 — What’s New?” series. We will take a closer look at some of the features and updates in Android 14. This is a non-exhaustive list and only covers some of the more exciting new developments. These are based on what’s available in Android 14 Beta 1 and the UpsideDownCake Preview revision 3. These APIs could change between the time of writing and the final release.

Screenshot Detection API

Android 14 introduces a new privacy-preserving Screenshot Detection API that allows apps to detect when a user takes a screenshot. The API lets the app register a callback at an activity level. When a screenshot is taken, a visual notification is shown and the callback is invoked. It is important to note that the callback doesn’t provide the image of the screenshot and as of now only supports screenshots taken with a specific combination of hardware button presses. Screenshots taken using adb command or instrumentation tests with DeviceCapture are not supported.

To get started, add the following permission to the manifest

<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />

In the activity, register and unregister the callback and implement the ScreenCaptureCallback interface

Android 14 Screenshot Callback on Activity

Alternatively, you can create an anonymous object of the interface and use it as follows

Android 14 Screenshot Callback as an object
Android 14 Screenshot Detection

If you are testing this out on an emulator, use this adb command to trigger the hardware combination for taking a screenshot.

adb shell input keyevent 120

Read more about this API over at Android Developers

Selected Photo Access

Android 14 builds on top of the privacy features in previous versions of Android. This new feature allows a user to grant access to specific media files when an app requests visual media permissions READ_MEDIA_IMAGES or READ_MEDIA_VIDEO, first introduced in Android 13. To enable this feature, READ_MEDIA_VISUAL_USER_SELECTED permission has to be declared and requested along with the appropriate media permission.

With the change in the API, the permission dialog will now show the following options

Android 14 Selected Photo Access Permission Dialog
  • Select photos, as the name suggests, grants permission for the user-selected photo option
  • Allow all, behaves like Android 13, and grants read permission for all media
  • Don’t allow, behaves like Android 13, and denies read permission

There’s a behavioral change with the new permission that needs to be accounted for. When the new permission is declared and requested, the permission controller is made aware of the fact the user can re-request the media permission to select more photos and videos. If the user selects Select Photos, the following happens

  • The READ_MEDIA_IMAGES and READ_MEDIA_VIDEO permissions are both denied.
  • The READ_MEDIA_VISUAL_USER_SELECTED permission is granted, providing partial and temporary access to the user's photos and videos.

In order to get access to other photos and videos, media permissions must be requested again

Read more about this on Android Developers

Back Gesture Preview

Technically available in Android 13 as an early preview, Android 14 stable is expected to come with full predictive back gesture support out of the box. When fully implemented, it lets users preview the destination or result of the back gesture, allowing them to decide if they want to stay or continue with the gesture.

With Android 14, supporting Predictive Back Gesture is as easy as adding this entry in <application> tag of your manifest.

Android 14 back Invoke callback flag

To see it in action, enable the feature toggle in the Developer options.

Android 14 Predictive Back Gesture

Read more about the predictive back gesture at Android Developers.

Part 2 covers a couple of other new APIs like Grammatical Infliction API and custom actions in Intent Chooser, do check it out!

All the new APIs mentioned above in this article and the second article can be checked out using the sample app on GitHub.

For regular updates and more Android goodness, follow me on my socials and follow me on Medium while you are at it!

LinkedIn

If you want to support me with the work I do, feel free to buy me a coffee!

--

--