Deep Dive into TvProvider APIs

Last night at Google I/O a session was hosted about Android TV. Along with this new UI there was documentation posted about the new way apps can interface with it, using the APIs. This gives a lot of information about how this experience will work, as well as raising a few questions about how the experience will work.

Apps are using the Tv Input Framework

The APIs to add channels and programs may look pretty familiar.

Uri channelUri = context.getContentResolver().insert(
TvContractCompat.Channels.CONTENT_URI, builder.build().toContentValues());

They actually are using the same APIs for Live Channels and the Tv Input Framework. To designate it as a channel to appear on the launcher, they are marked with TvContractCompat.Channels.TYPE_PREVIEW.

Looking at the new TvProvider support library, it does seem to have a number of similarities with the TIF Companion Library with the Channel and Program classes. This support library also includes backported data columns and some more abstract classes. This is probably the future of the library.

compile 'com.android.support:support-tv-provider:26.0.0-beta1'

There is also a channel logo each must provide. In staying with Google’s recent theme of circles for everything, these logos are masked into a circle.

Using a JobService or any other way, these channels can be continually updated with new programs to keep users engaged. They are added similar to the programs in Live Channel’s TV guide, except these do not require static start and end times. They all appear as on-demand content which can be selected.

Channel Order

The first row is the app drawer and the second is your Watch Next. Every other channel is added underneath, in a seemingly chronological order. Apps must be in the foreground when they request to add new channels. Apps don’t have much control over where these new channels appear. There didn’t seem to be a way to move channels up and down, but that feature will likely appear.

TvContractCompat.requestChannelBrowsable(context, channelId);

This command opens up a dialog which requires user consent to add a channel, except for the first channel the app adds. Apps receive an intent when an app is first installed. This allows them to immediately add content to the homescreen for users.

This can also be controlled in settings. For example, YouTube will have three channels. Trending may be the only one shown at first, but two more are for your Recommended videos and 360-degree videos, which is coming to the new YouTube app.

Watch Next

Adding programs to the Watch Next list is pretty much the same as its own channel.

Uri watchNextProgramUri = context.getContentResolver()
.insert(TvContractCompat.WatchNextPrograms.CONTENT_URI, builder.build().toContentValues());

The programs are just inserted, and can later be updated or removed. These programs can have a large number of properties.

WatchNextProgram.Builder builder = new WatchNextProgram.Builder();
builder.setType(TvContractCompat.WatchNextPrograms.TYPE_CLIP)
.setWatchNextType(TvContractCompat.WatchNextPrograms.WATCH_NEXT_TYPE_CONTINUE)
.setLastEngagementTimeUtcMillis(time)
.setTitle("Title")
.setDescription("Program description")
.setPosterArtUri(uri)
.setIntentUri(uri)
.setInternalProviderId(appProgramId);

Of note are the WatchNextType, which shows the type of suggestion. This might be “Continue”, “New”, “Watch Next”, or “Watchlist”. There is also the LastEngagement, which may be used for ordering the items in the queue. This time is simply the last time I watched the content.

How does this affect apps?

Reading through this guide, it makes me wonder how this will affect many apps, some of which I’ve written. Adding support for this feature isn’t hard, and this is one way to improve engagement between users and content.

It certainly moves away from the linear Live Channels system. Of course, live events and streams may still appear in the launcher, but it isn’t necessary. Apps like Cumulus TV may place each user-generated channel in its own “program” and everything is shown in a single row, with video previews.

Google will be working with third-party apps like Netflix, as well as their own apps like YouTube. So we will have numerous examples of how this feature should be implemented. Unlike the current launcher, this one is more opinionated. What do you think? Let us know in the comments below.

Nick Felker

Nick Felker is a student Electrical & Computer Engineering student at Rowan University (C/O 2017) and the student IEEE webmaster. When he's not studying, he is a software developer for the web and Android (Felker Tech). He has several open source projects on GitHub Devices: Moto G-2013 Moto G-2015, Moto 360, Google ADT-1, Nexus 7-2013 (x2), Lenovo Laptop, Custom Desktop. Although he was an intern at Google, the content of this blog is entirely independent and his own thoughts.

More Posts - Website

Follow Me:

  • Abhilash Bingi

    I was initially concerned that most apps will get hidden, but as I read about it more, I’m not so concerned coz apps get to add a channel row anyway. Is there a limit to how many favorite apps appear in the first row?

    Also Games seem to be completely left out in the talk and demos. I wonder how they’ll look when Android O comes to the Shield.

    • I’m unsure as to both. Games were mentioned at the Q&A, although it’s not clear if NVIDIA will be able to add a custom row for all your games.

  • Patrick LaRocque

    What hardware are they using for demos? The Shield TV? Nexus Player? Something new?

    • Kawshik Ahmed

      They used the SHIELD when demoing Google Assistant and when they were showing Android O they were using the Nexus Player. They even said the word Nexus Player in the Android TV session.

      • Patrick LaRocque

        That’s surprising, I thought the Nexus Player was EOL. Part of me was hoping there would be a new nexus player announced. The Shield TV looks great, but a little too powerful for what I need. I wouldn’t game on it so having to pay for a game controller as a part of the system cost isn’t appealing to me.

        • Kevin Brosseau

          Nah, in fact the Beta OTA image is up for you to install if you want. The Nexus Player is their only device they have for Android TV that they directly control. And I don’t think they’re in a hurry to make a new one either.

          • Patrick LaRocque

            It’s too bad the performance on the thing is so poor. I think I’m finally going to break down and buy a Shield TV. I’m tired of stuttering Netflix, Google Play Movies, and even directly streamed videos from Plex. I have a wired USB network adapter on it and the only way to fix these issues is the occasional reboot. After a fresh reboot things seem fine for a little while which is why I haven’t replaced it yet. I am fine with apps loading slow or even a stutter in the menus once in a while, but video playback needs to be smooth.

    • They are using the Nexus Player. There is an Android O build for it.