Work with channel data

Your TV input must provide Electronic Program Guide (EPG) data for at least
one channel in its setup activity. You should also periodically update that
data, with consideration for the size of the update and the processing thread
that handles it. Additionally, you can provide app links for channels
that guide the user to related content and activities.
This lesson discusses creating and updating channel and program data on the
system database with these considerations in mind.

Register channels in the database

The Android TV system database maintains records of channel data for TV inputs. In your setup
activity, for each of your channels, you must map your channel data to the following fields of the
TvContract.Channels class:

Although the TV input framework is generic enough to handle both traditional broadcast and
over-the-top (OTT) content without any distinction, you may want to define the following columns in
addition to those above to better identify traditional broadcast channels:

In the example above, channel is an object which holds channel metadata from the
backend server.

Present channel and program information

The system TV app presents channel and program information to users as they flip through channels,
as shown in figure 1. To make sure the channel and program information works with the system TV app's
channel and program information presenter, follow the guidelines below.

Note: Adding channel data to the ContentProvider
can take time. Add current programs (those within two hours of the current time)
only when you configure your EpgSyncJobService to update the rest
of the channel data in the background. See
the
Android TV Live TV Sample App for an example.

Process channel data asynchronously

Data manipulation, such as fetching a stream from the server or accessing the database, should
not block the UI thread. Using an AsyncTask is one
way to perform updates asynchronously. For example, when loading channel info from a backend server,
you can use AsyncTask as follows:

Add app link information

Channels can use app links to let users easily launch a related
activity while they are watching channel content. Channel apps use
app links to extend user engagement by launching activities that show
related information or additional content. For example, you can use app links
to do the following:

Guide the user to discover and purchase related content.

Provide additional information about currently playing content.

While viewing episodic content, start viewing the next episode in a
series.

App links are displayed when the user presses Select to show the
TV menu while watching channel content.

Figure 1. An example app link
displayed on the Channels row while channel content is shown.

When the user selects the app link, the system starts an activity using
an intent URI specified by the channel app. Channel content continues to play
while the app link activity is active. The user can return to the channel
content by pressing Back.

Provide app link channel data

Android TV automatically creates an app link for each channel,
using information from the channel data. To provide app link information,
specify the following details in your
TvContract.Channels fields:

COLUMN_APP_LINK_COLOR - The
accent color of the app link for this channel. For an example accent color,
see figure 2, callout 3.

COLUMN_APP_LINK_ICON_URI -
The URI for the app badge icon of the app link for this channel. For an
example app badge icon, see figure 2, callout 2.

For the poster image
(COLUMN_APP_LINK_POSTER_ART_URI),
the system uses the app's home screen banner. If the app doesn't provide a
banner, the system uses a default TV app image.

For the badge icon
(COLUMN_APP_LINK_ICON_URI), the
system uses a badge that shows the app name. If the system is also using the
app banner or default app image for the poster image, no app badge is shown.

You specify app link details for your channels in your app's
setup activity. You can update these app link details at any point, so
if an app link needs to match channel changes, update app
link details and call
ContentResolver.update() as needed. For more details on updating
channel data, see Update channel data.