Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/media/tv/AdRequest#constants) \| [Inherited Constants](https://developer.android.com/reference/android/media/tv/AdRequest#inhconstants) \| [Fields](https://developer.android.com/reference/android/media/tv/AdRequest#lfields) \| [Ctors](https://developer.android.com/reference/android/media/tv/AdRequest#pubctors) \| [Methods](https://developer.android.com/reference/android/media/tv/AdRequest#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/tv/AdRequest#inhmethods)

# AdRequest

*** ** * ** ***

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


`
public

final

class
AdRequest
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/android/os/Parcelable


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.tv.AdRequest |

<br />

*** ** * ** ***

An advertisement request which can be sent to TV input to request AD operations.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_START` Request to start an advertisement. |
| `int` | `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_STOP` Request to stop an advertisement. |

| ### Inherited constants |
|---|
| From interface `https://developer.android.com/reference/android/os/Parcelable` |---|---| | `int` | `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor. | | `int` | `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`". | |

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/media/tv/AdRequest>` | `https://developer.android.com/reference/android/media/tv/AdRequest#CREATOR` |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/tv/AdRequest#AdRequest(int,%20int,%20android.net.Uri,%20long,%20long,%20long,%20android.os.Bundle)(int id, int requestType, https://developer.android.com/reference/android/net/Uri uri, long startTime, long stopTime, long echoInterval, https://developer.android.com/reference/android/os/Bundle metadata) ` |
| ` https://developer.android.com/reference/android/media/tv/AdRequest#AdRequest(int,%20int,%20android.os.ParcelFileDescriptor,%20long,%20long,%20long,%20java.lang.String,%20android.os.Bundle)(int id, int requestType, https://developer.android.com/reference/android/os/ParcelFileDescriptor fileDescriptor, long startTime, long stopTime, long echoInterval, https://developer.android.com/reference/java/lang/String mediaFileType, https://developer.android.com/reference/android/os/Bundle metadata) ` |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/media/tv/AdRequest#describeContents()() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
| ` long` | ` https://developer.android.com/reference/android/media/tv/AdRequest#getEchoIntervalMillis()() ` Gets the echo interval in milliseconds. |
| ` https://developer.android.com/reference/android/os/ParcelFileDescriptor` | ` https://developer.android.com/reference/android/media/tv/AdRequest#getFileDescriptor()() ` Gets the file descriptor of the AD media. |
| ` int` | ` https://developer.android.com/reference/android/media/tv/AdRequest#getId()() ` Gets the ID of AD request. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/media/tv/AdRequest#getMediaFileType()() ` Gets the media file type such as mp4, mob, avi. |
| ` https://developer.android.com/reference/android/os/Bundle` | ` https://developer.android.com/reference/android/media/tv/AdRequest#getMetadata()() ` Gets the metadata of the media file. |
| ` int` | ` https://developer.android.com/reference/android/media/tv/AdRequest#getRequestType()() ` Gets the request type. |
| ` long` | ` https://developer.android.com/reference/android/media/tv/AdRequest#getStartTimeMillis()() ` Gets the start time of the AD media in milliseconds. |
| ` long` | ` https://developer.android.com/reference/android/media/tv/AdRequest#getStopTimeMillis()() ` Gets the stop time of the AD media in milliseconds. |
| ` https://developer.android.com/reference/android/net/Uri` | ` https://developer.android.com/reference/android/media/tv/AdRequest#getUri()() ` Gets the URI of the AD media. |
| ` void` | ` https://developer.android.com/reference/android/media/tv/AdRequest#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) ` Flatten this object in to a Parcel. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/android/os/Parcelable ` |---|---| | ` abstract int` | ` https://developer.android.com/reference/android/os/Parcelable#describeContents()() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. | | ` abstract void` | ` https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) ` Flatten this object in to a Parcel. | ||

## Constants

### REQUEST_TYPE_START

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

```
public static final int REQUEST_TYPE_START
```

Request to start an advertisement.

<br />

Constant Value:

1
(0x00000001)


### REQUEST_TYPE_STOP

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

```
public static final int REQUEST_TYPE_STOP
```

Request to stop an advertisement.

<br />

Constant Value:

2
(0x00000002)


## Fields

### CREATOR

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

```
public static final Creator<AdRequest> CREATOR
```

<br />

<br />

## Public constructors

### AdRequest

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

```
public AdRequest (int id, 
                int requestType, 
                Uri uri, 
                long startTime, 
                long stopTime, 
                long echoInterval, 
                Bundle metadata)
```

<br />

<br />

| Parameters ||
|---|---|
| `id` | `int` <br /> |
| `requestType` | `int`: Value is one of the following: - `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_START` - `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_STOP` |
| `uri` | `Uri`: This value may be `null`. <br /> |
| `startTime` | `long` <br /> |
| `stopTime` | `long` <br /> |
| `echoInterval` | `long` <br /> |
| `metadata` | `Bundle`: This value cannot be `null`. <br /> |

### AdRequest

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

```
public AdRequest (int id, 
                int requestType, 
                ParcelFileDescriptor fileDescriptor, 
                long startTime, 
                long stopTime, 
                long echoInterval, 
                String mediaFileType, 
                Bundle metadata)
```

<br />

<br />

| Parameters ||
|---|---|
| `id` | `int` <br /> |
| `requestType` | `int`: Value is one of the following: - `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_START` - `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_STOP` |
| `fileDescriptor` | `ParcelFileDescriptor`: This value may be `null`. <br /> |
| `startTime` | `long` <br /> |
| `stopTime` | `long` <br /> |
| `echoInterval` | `long` <br /> |
| `mediaFileType` | `String`: This value may be `null`. <br /> |
| `metadata` | `Bundle`: This value cannot be `null`. <br /> |

## Public methods

### describeContents

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

```
public int describeContents ()
```

Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation. For example, if the object will
include a file descriptor in the output of `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`,
the return value of this method must include the
`https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` bit.

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### getEchoIntervalMillis

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

```
public long getEchoIntervalMillis ()
```

Gets the echo interval in milliseconds.

The interval TV input needs to echo and inform TV interactive app service the video
playback elapsed time.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/tv/AdResponse`

### getFileDescriptor

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

```
public ParcelFileDescriptor getFileDescriptor ()
```

Gets the file descriptor of the AD media.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/ParcelFileDescriptor` | The file descriptor of the AD media. Can be `null` for `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_STOP` or a URI is used. <br /> |

### getId

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

```
public int getId ()
```

Gets the ID of AD request.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getMediaFileType

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

```
public String getMediaFileType ()
```

Gets the media file type such as mp4, mob, avi.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The media file type. Can be `null` for `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_STOP`. <br /> |

### getMetadata

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

```
public Bundle getMetadata ()
```

Gets the metadata of the media file.

This includes additional information the TV input needs to play the AD media. This may
include fields in `https://developer.android.com/reference/android/media/MediaFormat` like
`https://developer.android.com/reference/android/media/MediaFormat#KEY_SAMPLE_RATE`, or integrity information like SHA. What
data is included depends on the format of the media file.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Bundle` | The metadata of the media file. Can be an empty bundle for `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_STOP`. This value cannot be `null`. <br /> |

### getRequestType

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

```
public int getRequestType ()
```

Gets the request type.

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_START` - `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_STOP` |

### getStartTimeMillis

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

```
public long getStartTimeMillis ()
```

Gets the start time of the AD media in milliseconds.

0 means start immediately

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getStopTimeMillis

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

```
public long getStopTimeMillis ()
```

Gets the stop time of the AD media in milliseconds.

-1 means until the end

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getUri

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

```
public Uri getUri ()
```

Gets the URI of the AD media.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/Uri` | The URI of the AD media. Can be `null` for `https://developer.android.com/reference/android/media/tv/AdRequest#REQUEST_TYPE_STOP` or a file descriptor is used. <br /> |

### writeToParcel

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

```
public void writeToParcel (Parcel dest, 
                int flags)
```

Flatten this object in to a Parcel.

<br />

| Parameters ||
|---|---|
| `dest` | `Parcel`: This value cannot be `null`. <br /> |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` |