# TvAdService.Session

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Session

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/tv/ad/TvAdService.Session "View this page in Java")  

```
abstract class Session : KeyEvent.Callback
```

|---|------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                     ||
| ↳ | [android.media.tv.ad.TvAdService.Session](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#) |

Base class for derived classes to implement to provide a TV AD session.

## Summary

|                                                                                                                         Public constructors                                                                                                                          ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Session](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#Session(android.content.Context))`(`context:` `[Context](https://developer.android.com/reference/kotlin/android/content/Context.html#)`)` Creates a new Session. |

|                                                                                                                                                                                                                                                                                                                                                                                                           Public methods                                                                                                                                                                                                                                                                                                                                                                                                           ||
|--------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)     | [isMediaViewEnabled](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#isMediaViewEnabled())`()` Returns`true`if media view is enabled,`false`otherwise.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [layoutSurface](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#layoutSurface(kotlin.Int,%20kotlin.Int,%20kotlin.Int,%20kotlin.Int))`(`left:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `top:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `right:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `bottom:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Assigns a size and position to the surface passed in[onSetSurface](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)). |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [notifySessionStateChanged](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#notifySessionStateChanged(kotlin.Int,%20kotlin.Int))`(`state:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `err:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Notifies when the session state is changed.                                                                                                                                                                                                                                                                                                                                      |
| open[View](https://developer.android.com/reference/kotlin/android/view/View.html#)?        | [onCreateMediaView](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onCreateMediaView())`()` Called when the application requests to create a media view.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onCurrentChannelUri](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onCurrentChannelUri(android.net.Uri))`(`channelUri:` `[Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#)?`)` Receives current channel URI.                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onCurrentTvInputId](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onCurrentTvInputId(kotlin.String))`(`inputId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`)` Receives current TV input ID.                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onCurrentVideoBounds](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onCurrentVideoBounds(android.graphics.Rect))`(`bounds:` `[Rect](https://developer.android.com/reference/kotlin/android/graphics/Rect.html#)`)` Receives current video bounds.                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onError](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onError(kotlin.String,%20android.os.Bundle))`(`errMsg:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `params:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)`)` Called when the application sends information of an error.                                                                                                                                                                                                                                                                                                                                 |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)     | [onGenericMotionEvent](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onGenericMotionEvent(android.view.MotionEvent))`(`event:` `[MotionEvent](https://developer.android.com/reference/kotlin/android/view/MotionEvent.html#)`)` Implement this method to handle generic motion events on the current session.                                                                                                                                                                                                                                                                                                                                                                                 |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)     | [onKeyDown](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onKeyDown(kotlin.Int,%20android.view.KeyEvent))`(`keyCode:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `event:` `[KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#)?`)` Called when a key down event has occurred.                                                                                                                                                                                                                                                                                                                                           |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)     | [onKeyLongPress](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onKeyLongPress(kotlin.Int,%20android.view.KeyEvent))`(`keyCode:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `event:` `[KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#)?`)` Called when a long press has occurred.                                                                                                                                                                                                                                                                                                                                     |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)     | [onKeyMultiple](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onKeyMultiple(kotlin.Int,%20kotlin.Int,%20android.view.KeyEvent))`(`keyCode:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `count:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `event:` `[KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#)?`)` Called when a user's interaction with an analog control, such as flinging a trackball, generates simulated down/up events for the same key multiple times in quick succession.                                                                                          |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)     | [onKeyUp](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onKeyUp(kotlin.Int,%20android.view.KeyEvent))`(`keyCode:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `event:` `[KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#)?`)` Called when a key up event has occurred.                                                                                                                                                                                                                                                                                                                                                 |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onMediaViewSizeChanged](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onMediaViewSizeChanged(kotlin.Int,%20kotlin.Int))`(`width:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `height:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Called when the size of the media view is changed by the application.                                                                                                                                                                                                                                                                                                               |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [onRelease](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onRelease())`()` Releases TvAdService session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onResetAdService](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onResetAdService())`()` Resets TvAdService session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| abstract[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [onSetSurface](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface))`(`surface:` `[Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)?`)` Called when the application sets the surface.                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onSigningResult](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onSigningResult(kotlin.String,%20kotlin.ByteArray))`(`signingId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `result:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`)` Receives signing result.                                                                                                                                                                                                                                                                                                                                          |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onStartAdService](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onStartAdService())`()` Starts TvAdService session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onStopAdService](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onStopAdService())`()` Stops TvAdService session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onSurfaceChanged](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onSurfaceChanged(kotlin.Int,%20kotlin.Int,%20kotlin.Int))`(`format:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `width:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `height:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Called after any structural changes (format or size) have been made to the surface passed in[onSetSurface](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)).                                                    |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)     | [onTouchEvent](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onTouchEvent(android.view.MotionEvent))`(`event:` `[MotionEvent](https://developer.android.com/reference/kotlin/android/view/MotionEvent.html#)`)` Implement this method to handle touch screen motion events on the current session.                                                                                                                                                                                                                                                                                                                                                                                            |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onTrackInfoList](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onTrackInfoList(kotlin.collections.MutableList))`(`tracks:` `[MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)<[TvTrackInfo](https://developer.android.com/reference/kotlin/android/media/tv/TvTrackInfo.html#)!>`)` Receives track list.                                                                                                                                                                                                                                                                                                                               |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)     | [onTrackballEvent](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onTrackballEvent(android.view.MotionEvent))`(`event:` `[MotionEvent](https://developer.android.com/reference/kotlin/android/view/MotionEvent.html#)`)` Implement this method to handle trackball events on the current session.                                                                                                                                                                                                                                                                                                                                                                                              |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onTvInputSessionData](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onTvInputSessionData(kotlin.String,%20android.os.Bundle))`(`type:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `data:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)`)` Called when data from the linked[android.media.tv.TvInputService](https://developer.android.com/reference/kotlin/android/media/tv/TvInputService.html#)is received.                                                                                                                                                                                                  |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [onTvMessage](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onTvMessage(kotlin.Int,%20android.os.Bundle))`(`type:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `data:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)`)` Called when a TV message is received                                                                                                                                                                                                                                                                                                                                                            |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [requestCurrentChannelUri](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#requestCurrentChannelUri())`()` Requests the URI of the current channel.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [requestCurrentTvInputId](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#requestCurrentTvInputId())`()` Requests current TV input ID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [requestCurrentVideoBounds](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#requestCurrentVideoBounds())`()` Requests the bounds of the current video.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [requestSigning](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#requestSigning(kotlin.String,%20kotlin.String,%20kotlin.String,%20kotlin.ByteArray))`(`signingId:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `algorithm:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `alias:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `data:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)`)` Requests signing of the given data.                                                                                                   |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [requestTrackInfoList](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#requestTrackInfoList())`()` Requests the list of[TvTrackInfo](https://developer.android.com/reference/kotlin/android/media/tv/TvTrackInfo.html#).                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [sendTvAdSessionData](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#sendTvAdSessionData(kotlin.String,%20android.os.Bundle))`(`type:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `data:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)`)` Sends data related to this session to corresponding linked[android.media.tv.TvInputService](https://developer.android.com/reference/kotlin/android/media/tv/TvInputService.html#)object via TvView.                                                                                                                                                                    |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)           | [setMediaViewEnabled](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#setMediaViewEnabled(kotlin.Boolean))`(`enable:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Enables or disables the media view.                                                                                                                                                                                                                                                                                                                                                                                                                                                |

## Public constructors

### Session

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Session(context: Context)
```

Creates a new Session.

|                                                                          Parameters                                                                           ||
|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| `context` | [Context](https://developer.android.com/reference/kotlin/android/content/Context.html#):The context of the application This value cannot be`null`. |

## Public methods

### isMediaViewEnabled

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun isMediaViewEnabled(): Boolean
```

Returns`true`if media view is enabled,`false`otherwise.  
**See Also**

- [#setMediaViewEnabled(boolean)](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#setMediaViewEnabled(kotlin.Boolean))  

### layoutSurface

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun layoutSurface(
    left: Int, 
    top: Int, 
    right: Int, 
    bottom: Int
): Unit
```

Assigns a size and position to the surface passed in[onSetSurface](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)). The position is relative to the overlay view that sits on top of this surface.  
If you override this method you*must*call through to the superclass implementation.

|                                                                  Parameters                                                                   ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------|
| `left`   | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Left position in pixels, relative to the overlay view.   |
| `top`    | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Top position in pixels, relative to the overlay view.    |
| `right`  | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Right position in pixels, relative to the overlay view.  |
| `bottom` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Bottom position in pixels, relative to the overlay view. |

### notifySessionStateChanged

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun notifySessionStateChanged(
    state: Int, 
    err: Int
): Unit
```

Notifies when the session state is changed.  
If you override this method you*must*call through to the superclass implementation.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `state` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the current session state. Value is[android.media.tv.ad.TvAdManager#SESSION_STATE_STOPPED](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#SESSION_STATE_STOPPED:kotlin.Int),[android.media.tv.ad.TvAdManager#SESSION_STATE_RUNNING](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#SESSION_STATE_RUNNING:kotlin.Int), or[android.media.tv.ad.TvAdManager#SESSION_STATE_ERROR](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#SESSION_STATE_ERROR:kotlin.Int)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `err`   | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the error code for error state.[TvAdManager.ERROR_NONE](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#ERROR_NONE:kotlin.Int)is used when the state is not[TvAdManager.SESSION_STATE_ERROR](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#SESSION_STATE_ERROR:kotlin.Int). Value is[android.media.tv.ad.TvAdManager#ERROR_NONE](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#ERROR_NONE:kotlin.Int),[android.media.tv.ad.TvAdManager#ERROR_UNKNOWN](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#ERROR_UNKNOWN:kotlin.Int),[android.media.tv.ad.TvAdManager#ERROR_NOT_SUPPORTED](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#ERROR_NOT_SUPPORTED:kotlin.Int),[android.media.tv.ad.TvAdManager#ERROR_WEAK_SIGNAL](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#ERROR_WEAK_SIGNAL:kotlin.Int),[android.media.tv.ad.TvAdManager#ERROR_RESOURCE_UNAVAILABLE](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#ERROR_RESOURCE_UNAVAILABLE:kotlin.Int),[android.media.tv.ad.TvAdManager#ERROR_BLOCKED](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#ERROR_BLOCKED:kotlin.Int),[android.media.tv.ad.TvAdManager#ERROR_ENCRYPTED](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#ERROR_ENCRYPTED:kotlin.Int), or[android.media.tv.ad.TvAdManager#ERROR_UNKNOWN_CHANNEL](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#ERROR_UNKNOWN_CHANNEL:kotlin.Int) |

### onCreateMediaView

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onCreateMediaView(): View?
```

Called when the application requests to create a media view. Each session implementation can override this method and return its own view.

|                                                                         Return                                                                          ||
|---------------------------------------------------------------------------------|------------------------------------------------------------------------|
| [View](https://developer.android.com/reference/kotlin/android/view/View.html#)? | a view attached to the media window.`null`if no media view is created. |

### onCurrentChannelUri

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onCurrentChannelUri(channelUri: Uri?): Unit
```

Receives current channel URI.

|                                                     Parameters                                                      ||
|--------------|-------------------------------------------------------------------------------------------------------|
| `channelUri` | [Uri](https://developer.android.com/reference/kotlin/android/net/Uri.html#)?:This value may be`null`. |

### onCurrentTvInputId

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onCurrentTvInputId(inputId: String?): Unit
```

Receives current TV input ID.

|                                                      Parameters                                                       ||
|-----------|------------------------------------------------------------------------------------------------------------|
| `inputId` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:This value may be`null`. |

### onCurrentVideoBounds

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onCurrentVideoBounds(bounds: Rect): Unit
```

Receives current video bounds.

|                                                                                  Parameters                                                                                  ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `bounds` | [Rect](https://developer.android.com/reference/kotlin/android/graphics/Rect.html#):the rectangle area for rendering the current video. This value cannot be`null`. |

### onError

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onError(
    errMsg: String, 
    params: Bundle
): Unit
```

Called when the application sends information of an error.

|                                                                                                                                                                                                                                                                                                                            Parameters                                                                                                                                                                                                                                                                                                                             ||
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `errMsg` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the message of the error. This value cannot be`null`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `params` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#):additional parameters of the error. For example, the signingId of[android.media.tv.ad.TvAdView.TvAdCallback#onRequestSigning(java.lang.String,java.lang.String,java.lang.String,java.lang.String,byte[])](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdView.TvAdCallback#onRequestSigning(kotlin.String,%20kotlin.String,%20kotlin.String,%20kotlin.String,%20kotlin.ByteArray))can be included to identify the related signing request, and the method name "onRequestSigning" can also be added to the params. This value cannot be`null`. |

**See Also**

- [android.media.tv.ad.TvAdView#ERROR_KEY_METHOD_NAME](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdView#ERROR_KEY_METHOD_NAME:kotlin.String)  

### onGenericMotionEvent

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onGenericMotionEvent(event: MotionEvent): Boolean
```

Implement this method to handle generic motion events on the current session.

|                                                                             Parameters                                                                             ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `event` | [MotionEvent](https://developer.android.com/reference/kotlin/android/view/MotionEvent.html#):The motion event being received. This value cannot be`null`. |

|                                                                                                    Return                                                                                                     ||
|------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | If you handled the event, return`true`. If you want to allow the event to be handled by the next receiver, return`false`. |

**See Also**

- [android.view.View#onGenericMotionEvent](https://developer.android.com/reference/kotlin/android/view/View.html#onGenericMotionEvent(android.view.MotionEvent))  

### onKeyDown

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onKeyDown(
    keyCode: Int, 
    event: KeyEvent?
): Boolean
```

Called when a key down event has occurred. If you return true, you can first call[KeyEvent.startTracking()](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#startTracking())to have the framework track the event through its[onKeyUp(int,android.view.KeyEvent)](https://developer.android.com/reference/kotlin/android/view/KeyEvent.Callback.html#onKeyUp(kotlin.Int,%20android.view.KeyEvent))and also call your[onKeyLongPress(int,android.view.KeyEvent)](https://developer.android.com/reference/kotlin/android/view/KeyEvent.Callback.html#onKeyLongPress(kotlin.Int,%20android.view.KeyEvent))if it occurs.

|                                                         Parameters                                                          ||
|-----------|------------------------------------------------------------------------------------------------------------------|
| `keyCode` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The value in event.getKeyCode().      |
| `event`   | [KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#)?:This value may be`null`. |

|                                                                                                   Return                                                                                                    ||
|------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |

### onKeyLongPress

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onKeyLongPress(
    keyCode: Int, 
    event: KeyEvent?
): Boolean
```

Called when a long press has occurred. If you return true, the final key up will have[KeyEvent.FLAG_CANCELED](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#FLAG_CANCELED:kotlin.Int)and[KeyEvent.FLAG_CANCELED_LONG_PRESS](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#FLAG_CANCELED_LONG_PRESS:kotlin.Int)set. Note that in order to receive this callback, someone in the event change*must* return true from[onKeyDown](https://developer.android.com/reference/kotlin/android/view/KeyEvent.Callback.html#onKeyDown(kotlin.Int,%20android.view.KeyEvent))*and* call[KeyEvent.startTracking()](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#startTracking())on the event.

|                                                         Parameters                                                          ||
|-----------|------------------------------------------------------------------------------------------------------------------|
| `keyCode` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The value in event.getKeyCode().      |
| `event`   | [KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#)?:This value may be`null`. |

|                                                                                                   Return                                                                                                    ||
|------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |

### onKeyMultiple

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onKeyMultiple(
    keyCode: Int, 
    count: Int, 
    event: KeyEvent?
): Boolean
```

Called when a user's interaction with an analog control, such as flinging a trackball, generates simulated down/up events for the same key multiple times in quick succession.

|                                                                  Parameters                                                                  ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------|
| `keyCode` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The value in event.getKeyCode().                       |
| `count`   | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Number of pairs as returned by event.getRepeatCount(). |
| `event`   | [KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#)?:This value may be`null`.                  |

|                                                                                                   Return                                                                                                    ||
|------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |

### onKeyUp

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onKeyUp(
    keyCode: Int, 
    event: KeyEvent?
): Boolean
```

Called when a key up event has occurred.

|                                                         Parameters                                                          ||
|-----------|------------------------------------------------------------------------------------------------------------------|
| `keyCode` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The value in event.getKeyCode().      |
| `event`   | [KeyEvent](https://developer.android.com/reference/kotlin/android/view/KeyEvent.html#)?:This value may be`null`. |

|                                                                                                   Return                                                                                                    ||
|------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |

### onMediaViewSizeChanged

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onMediaViewSizeChanged(
    width: Int, 
    height: Int
): Unit
```

Called when the size of the media view is changed by the application.

This is always called at least once when the session is created regardless of whether the media view is enabled or not. The media view container size is the same as the containing[TvAdView](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdView). Note that the size of the underlying surface can be different if the surface was changed by calling[layoutSurface](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#layoutSurface(kotlin.Int,%20kotlin.Int,%20kotlin.Int,%20kotlin.Int)).

|                                                                            Parameters                                                                             ||
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `width`  | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The width of the media view, in pixels. The units of this value are pixels.  |
| `height` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The height of the media view, in pixels. The units of this value are pixels. |

### onRelease

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun onRelease(): Unit
```

Releases TvAdService session.  

### onResetAdService

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onResetAdService(): Unit
```

Resets TvAdService session.  

### onSetSurface

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun onSetSurface(surface: Surface?): Boolean
```

Called when the application sets the surface.

The TV AD service should render AD UI onto the given surface. When called with`null`, the AD service should immediately free any references to the currently set surface and stop using it.

|                                                                         Parameters                                                                         ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `surface` | [Surface](https://developer.android.com/reference/kotlin/android/view/Surface.html#)?:The surface to be used for AD UI rendering. Can be`null`. |

|                                                                     Return                                                                      ||
|------------------------------------------------------------------------------------|-------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true`if the surface was set successfully,`false`otherwise. |

### onSigningResult

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onSigningResult(
    signingId: String, 
    result: ByteArray
): Unit
```

Receives signing result.

|                                                                                                                                                                                                              Parameters                                                                                                                                                                                                               ||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `signingId` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the ID to identify the request. It's the same as the corresponding ID in[Session.requestSigning(String, String, String, byte[])](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#requestSigning(kotlin.String,%20kotlin.String,%20kotlin.String,%20kotlin.ByteArray))This value cannot be`null`. |
| `result`    | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html):the signed result. This value cannot be`null`.                                                                                                                                                                                                                                                                                   |

**See Also**

- [#requestSigning(String, String, String, byte[])](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#requestSigning(kotlin.String,%20kotlin.String,%20kotlin.String,%20kotlin.ByteArray))  

### onStartAdService

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onStartAdService(): Unit
```

Starts TvAdService session.  

### onStopAdService

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onStopAdService(): Unit
```

Stops TvAdService session.  

### onSurfaceChanged

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onSurfaceChanged(
    format: Int, 
    width: Int, 
    height: Int
): Unit
```

Called after any structural changes (format or size) have been made to the surface passed in[onSetSurface](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface)). This method is always called at least once, after[onSetSurface](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onSetSurface(android.view.Surface))is called with non-null surface.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `format` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The new[PixelFormat](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#)of the surface. Value is[android.graphics.PixelFormat#RGBA_8888](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_8888:kotlin.Int),[android.graphics.PixelFormat#RGBX_8888](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBX_8888:kotlin.Int),[android.graphics.PixelFormat#RGBA_F16](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_F16:kotlin.Int),[android.graphics.PixelFormat#RGBA_1010102](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_1010102:kotlin.Int),[android.graphics.PixelFormat#RGB_888](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGB_888:kotlin.Int),[android.graphics.PixelFormat#RGB_565](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGB_565:kotlin.Int), or android.graphics.PixelFormat.R_8 |
| `width`  | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The new width of the surface.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `height` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The new height of the surface.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |

### onTouchEvent

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onTouchEvent(event: MotionEvent): Boolean
```

Implement this method to handle touch screen motion events on the current session.

|                                                                             Parameters                                                                             ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `event` | [MotionEvent](https://developer.android.com/reference/kotlin/android/view/MotionEvent.html#):The motion event being received. This value cannot be`null`. |

|                                                                                                    Return                                                                                                     ||
|------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | If you handled the event, return`true`. If you want to allow the event to be handled by the next receiver, return`false`. |

**See Also**

- [android.view.View#onTouchEvent](https://developer.android.com/reference/kotlin/android/view/View.html#onTouchEvent(android.view.MotionEvent))  

### onTrackInfoList

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onTrackInfoList(tracks: MutableList<TvTrackInfo!>): Unit
```

Receives track list.

|                                                                                                                     Parameters                                                                                                                     ||
|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `tracks` | [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[TvTrackInfo](https://developer.android.com/reference/kotlin/android/media/tv/TvTrackInfo.html#)!\>:This value cannot be`null`. |

### onTrackballEvent

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onTrackballEvent(event: MotionEvent): Boolean
```

Implement this method to handle trackball events on the current session.

|                                                                             Parameters                                                                             ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `event` | [MotionEvent](https://developer.android.com/reference/kotlin/android/view/MotionEvent.html#):The motion event being received. This value cannot be`null`. |

|                                                                                                    Return                                                                                                     ||
|------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | If you handled the event, return`true`. If you want to allow the event to be handled by the next receiver, return`false`. |

**See Also**

- [android.view.View#onTrackballEvent](https://developer.android.com/reference/kotlin/android/view/View.html#onTrackballEvent(android.view.MotionEvent))  

### onTvInputSessionData

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onTvInputSessionData(
    type: String, 
    data: Bundle
): Unit
```

Called when data from the linked[android.media.tv.TvInputService](https://developer.android.com/reference/kotlin/android/media/tv/TvInputService.html#)is received.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ||
|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `type` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the type of the data This value cannot be`null`. Value is[android.media.tv.TvInputManager#SESSION_DATA_TYPE_TUNED](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#SESSION_DATA_TYPE_TUNED:kotlin.String),[android.media.tv.TvInputManager#SESSION_DATA_TYPE_TRACK_SELECTED](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#SESSION_DATA_TYPE_TRACK_SELECTED:kotlin.String),[android.media.tv.TvInputManager#SESSION_DATA_TYPE_TRACKS_CHANGED](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#SESSION_DATA_TYPE_TRACKS_CHANGED:kotlin.String),[android.media.tv.TvInputManager#SESSION_DATA_TYPE_VIDEO_AVAILABLE](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#SESSION_DATA_TYPE_VIDEO_AVAILABLE:kotlin.String),[android.media.tv.TvInputManager#SESSION_DATA_TYPE_VIDEO_UNAVAILABLE](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#SESSION_DATA_TYPE_VIDEO_UNAVAILABLE:kotlin.String),[android.media.tv.TvInputManager#SESSION_DATA_TYPE_BROADCAST_INFO_RESPONSE](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#SESSION_DATA_TYPE_BROADCAST_INFO_RESPONSE:kotlin.String),[android.media.tv.TvInputManager#SESSION_DATA_TYPE_AD_RESPONSE](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#SESSION_DATA_TYPE_AD_RESPONSE:kotlin.String),[android.media.tv.TvInputManager#SESSION_DATA_TYPE_AD_BUFFER_CONSUMED](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#SESSION_DATA_TYPE_AD_BUFFER_CONSUMED:kotlin.String), or[android.media.tv.TvInputManager#SESSION_DATA_TYPE_TV_MESSAGE](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#SESSION_DATA_TYPE_TV_MESSAGE:kotlin.String) |
| `data` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#):a bundle contains the data received This value cannot be`null`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

**See Also**

- [android.media.tv.TvInputService.Session#sendTvInputSessionData(String, Bundle)](https://developer.android.com/reference/kotlin/android/media/tv/TvInputService.Session.html#sendTvInputSessionData(kotlin.String,%20android.os.Bundle))
- [android.media.tv.ad.TvAdView#setTvView(TvView)](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdView#setTvView(android.media.tv.TvView))  

### onTvMessage

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onTvMessage(
    type: Int, 
    data: Bundle
): Unit
```

Called when a TV message is received

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ||
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `type` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The type of message received, such as[TvInputManager.TV_MESSAGE_TYPE_WATERMARK](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#TV_MESSAGE_TYPE_WATERMARK:kotlin.Int)Value is[android.media.tv.TvInputManager#TV_MESSAGE_TYPE_WATERMARK](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#TV_MESSAGE_TYPE_WATERMARK:kotlin.Int),[android.media.tv.TvInputManager#TV_MESSAGE_TYPE_CLOSED_CAPTION](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#TV_MESSAGE_TYPE_CLOSED_CAPTION:kotlin.Int), or[android.media.tv.TvInputManager#TV_MESSAGE_TYPE_OTHER](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#TV_MESSAGE_TYPE_OTHER:kotlin.Int)                                                                                                                                                                                                 |
| `data` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#):The raw data of the message. The bundle keys are:[TvInputManager.TV_MESSAGE_KEY_STREAM_ID](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#TV_MESSAGE_KEY_STREAM_ID:kotlin.String),[TvInputManager.TV_MESSAGE_KEY_GROUP_ID](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#TV_MESSAGE_KEY_GROUP_ID:kotlin.String),[TvInputManager.TV_MESSAGE_KEY_SUBTYPE](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#TV_MESSAGE_KEY_SUBTYPE:kotlin.String),[TvInputManager.TV_MESSAGE_KEY_RAW_DATA](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#TV_MESSAGE_KEY_RAW_DATA:kotlin.String). See[TvInputManager.TV_MESSAGE_KEY_SUBTYPE](https://developer.android.com/reference/kotlin/android/media/tv/TvInputManager.html#TV_MESSAGE_KEY_SUBTYPE:kotlin.String)for more information on how to parse this data. This value cannot be`null`. |

### requestCurrentChannelUri

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun requestCurrentChannelUri(): Unit
```

Requests the URI of the current channel.  
If you override this method you*must*call through to the superclass implementation.  

### requestCurrentTvInputId

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun requestCurrentTvInputId(): Unit
```

Requests current TV input ID.  
If you override this method you*must*call through to the superclass implementation.  
**See Also**

- [android.media.tv.TvInputInfo](https://developer.android.com/reference/kotlin/android/media/tv/TvInputInfo.html#)  

### requestCurrentVideoBounds

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun requestCurrentVideoBounds(): Unit
```

Requests the bounds of the current video.  
If you override this method you*must*call through to the superclass implementation.  

### requestSigning

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun requestSigning(
    signingId: String, 
    algorithm: String, 
    alias: String, 
    data: ByteArray
): Unit
```

Requests signing of the given data.

This is used when the corresponding server of the AD service app requires signing during handshaking, and the service doesn't have the built-in private key. The private key is provided by the content providers and pre-built in the related app, such as TV app.  
If you override this method you*must*call through to the superclass implementation.

|                                                                                                                                      Parameters                                                                                                                                       ||
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `signingId` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the ID to identify the request. When a result is received, this ID can be used to correlate the result with the request. This value cannot be`null`.                                    |
| `algorithm` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the standard name of the signature algorithm requested, such as MD5withRSA, SHA256withDSA, etc. The name is from standards like FIPS PUB 186-4 and PKCS #1. This value cannot be`null`. |
| `alias`     | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the alias of the corresponding[java.security.KeyStore](https://developer.android.com/reference/kotlin/java/security/KeyStore.html#). This value cannot be`null`.                        |
| `data`      | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html):the original bytes to be signed. This value cannot be`null`.                                                                                                                     |

**See Also**

- [#onSigningResult(String, byte[])](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdService.Session#onSigningResult(kotlin.String,%20kotlin.ByteArray))  

### requestTrackInfoList

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun requestTrackInfoList(): Unit
```

Requests the list of[TvTrackInfo](https://developer.android.com/reference/kotlin/android/media/tv/TvTrackInfo.html#).  
If you override this method you*must*call through to the superclass implementation.  

### sendTvAdSessionData

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun sendTvAdSessionData(
    type: String, 
    data: Bundle
): Unit
```

Sends data related to this session to corresponding linked[android.media.tv.TvInputService](https://developer.android.com/reference/kotlin/android/media/tv/TvInputService.html#)object via TvView.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ||
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `type` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):data type This value cannot be`null`. Value is[android.media.tv.ad.TvAdManager#SESSION_DATA_TYPE_AD_REQUEST](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#SESSION_DATA_TYPE_AD_REQUEST:kotlin.String),[android.media.tv.ad.TvAdManager#SESSION_DATA_TYPE_AD_BUFFER_READY](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#SESSION_DATA_TYPE_AD_BUFFER_READY:kotlin.String),[android.media.tv.ad.TvAdManager#SESSION_DATA_TYPE_BROADCAST_INFO_REQUEST](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#SESSION_DATA_TYPE_BROADCAST_INFO_REQUEST:kotlin.String), or[android.media.tv.ad.TvAdManager#SESSION_DATA_TYPE_REMOVE_BROADCAST_INFO_REQUEST](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdManager#SESSION_DATA_TYPE_REMOVE_BROADCAST_INFO_REQUEST:kotlin.String) |
| `data` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#):the related data values This value cannot be`null`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

**See Also**

- [android.media.tv.ad.TvAdView#setTvView(TvView)](https://developer.android.com/reference/kotlin/android/media/tv/ad/TvAdView#setTvView(android.media.tv.TvView))  

### setMediaViewEnabled

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun setMediaViewEnabled(enable: Boolean): Unit
```

Enables or disables the media view.

By default, the media view is disabled. Must be called explicitly after the session is created to enable the media view.

The TV AD service can disable its media view when needed.  
If you override this method you*must*call through to the superclass implementation.

|                                                                        Parameters                                                                         ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `enable` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):`true`if you want to enable the media view.`false`otherwise. |