Creating Home Channel on Android TV

Enes Varol
2 min readMar 4, 2022

Android TV ecosystem has many VoD/Streaming applications.

Let’s say you want to show your app content on the home screen like this:

Figure: Home Screen Channel Example

But How?

It is really simple to achieve it.

First Comes The Manifesto

We have to add “write EPG permissions” to our manifest file.

<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />

Then We Add the Library

I use Kotlin for my development and this is how we implement the library in Kotlin.

implementation("androidx.tvprovider:tvprovider:1.0.0")

Finally Some Coding!

Home channels consist of 2 items. Channel’s itself and programs that inside of the channel.

Figure: Home Screen Channel Items

So we need to create the channel and add programs to it.

To create a channel we need to do the following:

1- Create a Builder

val builder = Channel.Builder()
// Every channel you create must have the type TYPE_PREVIEW
builder.setType(TvContractCompat.Channels.TYPE_PREVIEW)
.setDisplayName("Play Movies & TV")
.setAppLinkIntentUri(uri)

Here Uri is where the app will go when a user selects the channel itself.

2- Insert Channel and Save Channel ID

var channelUri = context.contentResolver.insert(
TvContractCompat.Channels.CONTENT_URI, builder.build().toContentValues())
var channelId = ContentUris.parseId(channelUri)

What is My Channel Logo?

We must set the channel logo as well.

// Choose one or the other
// also works if logoUri is a URL
storeChannelLogo(context: Context, channelId: Long, logoUri: Uri)
storeChannelLogo(context: Context, channelId: Long, logo: Bitmap)

Note: Channel logo must be 80x80dp

If we want to make this channel appear on the screen automatically we must just type:

TvContractCompat.requestChannelBrowsable(context, channelId)

Note: Only one channel can automatically appear.

Time to Add Programs

The steps of adding a program are really similar to channel’s.

1- Create a builder

val builder = PreviewProgram.Builder()
builder.setChannelId(channelId)
.setType(TvContractCompat.PreviewPrograms.TYPE_CLIP)
.setTitle("Title")
.setDescription("Program description")
.setPosterArtUri(uri)
.setIntentUri(uri)
.setInternalProviderId(appProgramId)

2- Insert Program and Save Program ID

var programUri = context.contentResolver.insert(TvContractCompat.PreviewPrograms.CONTENT_URI,builder.build().toContentValues())
val programId = ContentUris.parseId(programUri)

That’s it!

Conclusion

We just made a very basic channel with one single program.

To get into more complexity and details, you can check out the:

Developer android page

--

--

Enes Varol

TRT - Android Developer GitHub/LinkedIn: vrolnes