Android M: What’s that “Broadcast Tile” for?
If you’ve spent any time poking around the System UI Tuner on Android M, you’ve likely noticed the option to add a “Broadcast Tile” to Quick Settings.
However, since there’s no documentation whatsoever explaining what this is used for or what the expected input is in the following dialog, I had to do some poking around in the source to figure it out.
Enter the IntentTile.
The IntentTile class is what the Broadcast Tile is represented by internally. The class QsTuner.java is what is used to configure the tile, and if you look at the isValid(String) method, it expects a string of alphanumeric characters or periods. Anything else will just be ignored.
So, with that said, you can now add a custom tile if you know the constraints. Let’s try something like ‘com.kcoppock.CUSTOMTILE’:
Press “OK”, and we should see the custom tile, using the text after the last ‘.’ in the entry:
However, that’s not enough to make it visible in the notification shade. Digging in a bit more to the IntentTile source, it turns out that the tile is invisible by default, and awaits an Intent to customize the tile and set it to visible in handleUpdateState().
The tile supports Intent parameters to set:
- Label
- Content Description
- Icon
- Click handler (Intent broadcast or PendingIntent)
- Long-Click handler (Intent broadcast or PendingIntent)
- Visibility
Given these configurations, we can make a Broadcast Tile do almost anything you can do in a standard Android application. If there’s an application that surfaces a public API through broadcasting Intents, you could add a Broadcast Tile that will send some information to that application, using an Intent broadcast. If you prefer to handle something internally in your own application, you can use a PendingIntent instead to deliver the Intent back to your process.
Note: using the Intent broadcast, the broadcast will be sent by the SystemUI process, so your receiver must be exported to receive the broadcast.
So I’ve put together a simple library project (just a single class + tests, currently) that simplifies the construction and configuration of a custom tile short of adding it through the System UI Tuner — that has to be done manually. It also includes a sample application demonstrating a usage of the library.
With it all put together, you now have a custom Quick Settings tile that you can assign up to two behaviors to:
Some caveats to keep in mind are:
- It doesn’t seem to be possible (at least not trivially) to check the current state of the tile to know if it is visible or invisible.
- The tile’s state does not persist across a device reboot, so it’s recommended to register an ACTION_BOOT_COMPLETED receiver to re-initialize the tile if it was previously configured.
- This is definitely not something you should build around for a publicly released app. There’s no publicly documented API for this and the current implementation is almost certainly going to change in a future Android OS release — especially if it ever becomes an official API (which I personally wouldn’t expect to happen).
I hope this is useful — I wasn’t able to find any existing discussions on how this tile worked. If you come up with an interesting use case for a custom tile, I’d love to hear about it! Also, if you see anything I missed, please let me know!
See: BroadcastTileSupport at GitHub