Device Controls
As was noted earlier, few significant user-facing new features were added in Android 11. One is “device controls”. Akin to how Android 8.0 allowed developers to offer items to show in the notification shade through a TileService
, Android 11 allows developers ControlsProviderService
.
In this chapter, we will explore what our options are for device controls.
The High-Level View
Android has long supported a “power menu” that is triggered by a long-press on the device’s POWER button. Traditionally, this had an option for a complete device shutdown, where a short press of the POWER button just turns off the screen. Later versions of Android started offering other items here, such as a device reboot or capturing of a screenshot. Android 11 restyles this “menu” once again, now taking up the entire screen… and part of that screen represents stuff that we as developers can control.
What the User Gets
If you long-press the POWER button on an Android 11 device, a screen akin to this one will appear:
In the middle of the screen is a “Device controls” card. Tapping that will display various sources of device controls:
Tapping one of those will give you a lineup of available devices to control, perhaps based on other configuration performed in the main app:
You can check and uncheck the checkboxes in the lower right corner of each of those tiles to determine which of these you want to appear on your “power menu”. They will then show up on the main “power menu” screen, and you can interact with them, as we will explore more later in this chapter.
How We Build It
Your graphic designers might look at this and envision all sorts of possibilities for what they might do in this space.
Your graphic designers will be very disappointed.
We do not directly control the look or interactivity of these tiles. Instead, we describe what we want in fairly generic terms (“we want the user to control a value in a range from 1 to 10”), and Android renders that how Android sees fit.
In this respect, this is reminiscent of Android 9.0’s flagship feature: slices. There, we did not provide the direct UI of a slice, but instead described the general structure of what we want, and the slice host would decide how to render that structure.
(and, if you forgot about slices, or never heard of them in the first place, you did not miss much…)
A subclass of ControlsProviderService
provides the API that you will expose to Android to supply the contents of these tiles. So, to offer device control tiles to your users, you will create a ControlsProviderService
subclass and implement its API to publish the roster of possible tiles and support the user interacting with a chosen subset of those tiles.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.