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 TvProvider 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

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 (http://github.com/fleker) 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:
TwitterLinkedInGoogle PlusReddit