# PreviewChannelHelper

# PreviewChannelHelper

Artifact:[androidx.tvprovider:tvprovider](https://developer.android.com/jetpack/androidx/releases/tvprovider)  
[View Source](https://cs.android.com/search?q=file:androidx/tvprovider/media/tv/PreviewChannelHelper.java+class:androidx.tvprovider.media.tv.PreviewChannelHelper)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/tvprovider/media/tv/PreviewChannelHelper "View this page in Java")

<br />

```
@WorkerThread
class PreviewChannelHelper
```

<br />

*** ** * ** ***

From a user's perspective, the TV home screen has two types of channels: the single Live Channels row versus the App preview Channels. This class is concerned with App Channels; or more precisely:*your*app's preview Channels. In API 26+, all TV apps are allowed to create multiple channels and publish those Channels to the home screen.

This class provides convenience methods to help you publish, update and delete channels; add, update or remove programs in a channel. You do not need to know anything about Content Providers, Content Resolvers, Cursors or such to publish your channels. This class abstracts away all database interactions for you.

To make it easy for you to distinguish classes that help you build App Channels, the support library uses the prefix Preview- to denote the classes that pertain to app Channels. Hence, the classes[PreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel)and[PreviewProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewProgram)help your app add channels to the TV home page. All calls to methods in the class should be made on worker threads.

## Summary

|                                                                                                                                                                                                                                         ### Public constructors                                                                                                                                                                                                                                          |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PreviewChannelHelper](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#PreviewChannelHelper(android.content.Context))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!)`                                                                                                                                                                                                                                    |
| [PreviewChannelHelper](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#PreviewChannelHelper(android.content.Context,int,int))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!,` ` urlConnectionTimeoutMillis: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` urlReadTimeoutMillis: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` |

|                                                                                                                                                  ### Public functions                                                                                                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                           | [deletePreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#deletePreviewChannel(long))`(channelId: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Removes a preview channel from the system's content provider (aka TvProvider).                                                                                                                                                                                                                                                                                                            |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                           | [deletePreviewProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#deletePreviewProgram(long))`(programId: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Removes programs from a preview channel.                                                                                                                                                                                                                                                                                                                                                  |
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[PreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel)`!>!` | [getAllChannels](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#getAllChannels())`()` The TvProvider does not allow select queries.                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [PreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel)`?`                                                                                                                                                                                                         | [getPreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#getPreviewChannel(long))`(channelId: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Retrieves a single preview channel from the TvProvider.                                                                                                                                                                                                                                                                                                                                         |
| [PreviewProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewProgram)`?`                                                                                                                                                                                                         | [getPreviewProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#getPreviewProgram(long))`(programId: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Retrieves a single preview program from the system content provider (aka TvProvider).                                                                                                                                                                                                                                                                                                           |
| [WatchNextProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/WatchNextProgram)`?`                                                                                                                                                                                                     | [getWatchNextProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#getWatchNextProgram(long))`(programId: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Retrieves a single WatchNext program from the system content provider (aka TvProvider).                                                                                                                                                                                                                                                                                                     |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                                                                                                                                                                           | [publishChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#publishChannel(androidx.tvprovider.media.tv.PreviewChannel))`(channel: `[PreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel)`)` Publishing a channel to the TV home screen is a two step process: first, you add the channel to the TV content provider; second, you make the channel browsable (i.e. visible).                                                                                                                                                   |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                                                                                                                                                                           | [publishDefaultChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#publishDefaultChannel(androidx.tvprovider.media.tv.PreviewChannel))`(channel: `[PreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel)`)` This is a convenience method that simply publishes your first channel for you.                                                                                                                                                                                                                                      |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                                                                                                                                                                           | [publishPreviewProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#publishPreviewProgram(androidx.tvprovider.media.tv.PreviewProgram))`(program: `[PreviewProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewProgram)`)` Adds programs to a preview channel.                                                                                                                                                                                                                                                                                 |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                                                                                                                                                                           | [publishWatchNextProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#publishWatchNextProgram(androidx.tvprovider.media.tv.WatchNextProgram))`(program: `[WatchNextProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/WatchNextProgram)`)` Adds a program to the Watch Next channel                                                                                                                                                                                                                                                                  |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                           | [updatePreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#updatePreviewChannel(long,androidx.tvprovider.media.tv.PreviewChannel))`(channelId: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, update: `[PreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel)`)` To update a preview channel, you need to use the[PreviewChannel.Builder](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel.Builder)to set the attributes you wish to change. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                           | [updatePreviewProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#updatePreviewProgram(long,androidx.tvprovider.media.tv.PreviewProgram))`(programId: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, update: `[PreviewProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewProgram)`)` Updates programs in a preview channel.                                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                           | [updateWatchNextProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#updateWatchNextProgram(androidx.tvprovider.media.tv.WatchNextProgram,long))`(upgrade: `[WatchNextProgram](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/WatchNextProgram)`, programId: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Updates a WatchNext program.                                                                                                                                                                               |

|                              ### Protected functions                              |
|-----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)`!` | [downloadBitmap](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#downloadBitmap(android.net.Uri))`(logoUri: `[Uri](https://developer.android.com/reference/android/net/Uri.html)`)` Downloads a Bitmap from a remote server. |

## Public constructors

### PreviewChannelHelper

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
PreviewChannelHelper(context: Context!)
```  

### PreviewChannelHelper

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
PreviewChannelHelper(
    context: Context!,
    urlConnectionTimeoutMillis: Int,
    urlReadTimeoutMillis: Int
)
```  

|                                                Parameters                                                 |
|-----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`             | the Context object that holds the channels                                                                         |
| `urlConnectionTimeoutMillis: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | see[setConnectTimeout](https://developer.android.com/reference/java/net/URLConnection.html#setConnectTimeout(int)) |
| `urlReadTimeoutMillis: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)       | see[setReadTimeout](https://developer.android.com/reference/java/net/URLConnection.html#setReadTimeout(int))       |

## Public functions

### deletePreviewChannel

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun deletePreviewChannel(channelId: Long): Unit
```

Removes a preview channel from the system's content provider (aka TvProvider).  

### deletePreviewProgram

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun deletePreviewProgram(programId: Long): Unit
```

Removes programs from a preview channel.  

### getAllChannels

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun getAllChannels(): (Mutable)List<PreviewChannel!>!
```

The TvProvider does not allow select queries. Hence, unless you are querying for a[single PreviewChannel by id](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#getPreviewChannel(long)), you must get all of your channels at once and then use the returned list as necessary.  

### getPreviewChannel

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun getPreviewChannel(channelId: Long): PreviewChannel?
```

Retrieves a single preview channel from the TvProvider. When you publish a preview channel, the TvProvider assigns an ID to it. That's the channelId to use here.  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|-------------------------------------|
| `channelId: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | ID of preview channel in TvProvider |

|                                                     Returns                                                     |
|-----------------------------------------------------------------------------------------------------------------|-------------------------------------|
| [PreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel)`?` | PreviewChannel or null if not found |

### getPreviewProgram

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun getPreviewProgram(programId: Long): PreviewProgram?
```

Retrieves a single preview program from the system content provider (aka TvProvider).  

### getWatchNextProgram

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun getWatchNextProgram(programId: Long): WatchNextProgram?
```

Retrieves a single WatchNext program from the system content provider (aka TvProvider).  

### publishChannel

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun publishChannel(channel: PreviewChannel): Long
```

Publishing a channel to the TV home screen is a two step process: first, you add the channel to the TV content provider; second, you make the channel browsable (i.e. visible).[This method](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#publishChannel(androidx.tvprovider.media.tv.PreviewChannel))adds the channel to the TV content provider for you and returns a channelId. Next you must use the channelId to make the channel browsable. There are two ways you can make a channel browsable: a) For your first channel, simply ask the system to make the channel browsable: TvContractCompat.requestChannelBrowsable(context,channelId) b) For any additional channel beyond the first channel, you must get permission from the user. So if this channel is not your first channel, you must request user permission through the following intent. So take the channelId returned by[this method](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#publishChannel(androidx.tvprovider.media.tv.PreviewChannel))and do the following inside an Activity or Fragment:  

```kotlin
intent = new Intent(TvContractCompat.ACTION_REQUEST_CHANNEL_BROWSABLE);
intent.putExtra(TvContractCompat.EXTRA_CHANNEL_ID, channelId);
startActivityForResult(intent, REQUEST_CHANNEL_BROWSABLE);
```

Creating a PreviewChannel, you may pass to the builder a[url as your logo](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel.Builder#setLogo(android.net.Uri)). In such case,[updatePreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#updatePreviewChannel(long,androidx.tvprovider.media.tv.PreviewChannel))will load the logo over the network. To use your own networking code, override[downloadBitmap](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#downloadBitmap(android.net.Uri)).  

|                                    Returns                                    |
|-------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | channelId or -1 if insertion fails. This is the id the system assigns to your published channel. You can use it later to get a reference to this published PreviewChannel. |

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |

### publishDefaultChannel

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun publishDefaultChannel(channel: PreviewChannel): Long
```

This is a convenience method that simply publishes your first channel for you. After calling[publishChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#publishChannel(androidx.tvprovider.media.tv.PreviewChannel))to add the channel to the TvProvider, it calls[requestChannelBrowsable](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/TvContractCompat#requestChannelBrowsable(android.content.Context,long))to make the channel visible.

Only use this method to publish your first channel as you do not need user permission to make your first channel browsable (i.e. visible on home screen). For additional channels, see the documentations for[publishChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#publishChannel(androidx.tvprovider.media.tv.PreviewChannel)).

Creating a PreviewChannel, you may pass to the builder a[url as your logo](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel.Builder#setLogo(android.net.Uri)). In such case,[updatePreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#updatePreviewChannel(long,androidx.tvprovider.media.tv.PreviewChannel))will load the logo over the network. To use your own networking code, override[downloadBitmap](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#downloadBitmap(android.net.Uri)).  

|                                    Returns                                    |
|-------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | channelId: This is the id the system assigns to your published channel. You can use it later to get a reference to this published PreviewChannel. |

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |

### publishPreviewProgram

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun publishPreviewProgram(program: PreviewProgram): Long
```

Adds programs to a preview channel.  

### publishWatchNextProgram

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun publishWatchNextProgram(program: WatchNextProgram): Long
```

Adds a program to the Watch Next channel  

### updatePreviewChannel

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun updatePreviewChannel(channelId: Long, update: PreviewChannel): Unit
```

To update a preview channel, you need to use the[PreviewChannel.Builder](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel.Builder)to set the attributes you wish to change. Then simply pass in the built channel and the channelId of the preview channel. (The channelId is the ID you received when you originally[published](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#publishChannel(androidx.tvprovider.media.tv.PreviewChannel))the preview channel.)

Creating a PreviewChannel, you may pass to the builder a[url as your logo](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannel.Builder#setLogo(android.net.Uri)). In such case,[updatePreviewChannel](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#updatePreviewChannel(long,androidx.tvprovider.media.tv.PreviewChannel))will load the logo over the network. To use your own networking code, override[downloadBitmap](https://developer.android.com/reference/kotlin/androidx/tvprovider/media/tv/PreviewChannelHelper#downloadBitmap(android.net.Uri)).  

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |

### updatePreviewProgram

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun updatePreviewProgram(programId: Long, update: PreviewProgram): Unit
```

Updates programs in a preview channel.  

### updateWatchNextProgram

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
fun updateWatchNextProgram(upgrade: WatchNextProgram, programId: Long): Unit
```

Updates a WatchNext program.  

## Protected functions

### downloadBitmap

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/tvprovider#1.1.0)  

```
protected fun downloadBitmap(logoUri: Uri): Bitmap!
```

Downloads a Bitmap from a remote server. It is declared protected to allow you to override it to use your own networking implementation if you so wish.  

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |