# MediaDrm.KeyRequest

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

# KeyRequest

*** ** * ** ***

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

```
class KeyRequest
```

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

Contains the opaque data an app uses to request keys from a license server. These request types may or may not be generated by a given plugin. Refer to plugin vendor documentation for more information.

## Summary

|                                                                                                                                                     Constants                                                                                                                                                      ||
|----------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [REQUEST_TYPE_INITIAL](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_INITIAL:kotlin.Int) Key request type is initial license request.                                            |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [REQUEST_TYPE_NONE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_NONE:kotlin.Int) Keys are already loaded and are available for use.                                            |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [REQUEST_TYPE_RELEASE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_RELEASE:kotlin.Int) Key request type is license release                                                     |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [REQUEST_TYPE_RENEWAL](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_RENEWAL:kotlin.Int) Key request type is license renewal.                                                    |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [REQUEST_TYPE_UPDATE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_UPDATE:kotlin.Int) Keys have been loaded but an additional license request is needed to update their values. |

|                                                                                                                                            Public methods                                                                                                                                             ||
|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html) | [getData](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#getData())`()` Get the opaque message data                                                                        |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)        | [getDefaultUrl](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#getDefaultUrl())`()` Get the default URL to use when sending the key request message to a server, if known. |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)              | [getRequestType](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#getRequestType())`()` Get the type of the request                                                          |

## Constants

### REQUEST_TYPE_INITIAL

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

```
static val REQUEST_TYPE_INITIAL: Int
```

Key request type is initial license request. A license request is necessary to load keys.  

    Value: 0

### REQUEST_TYPE_NONE

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

```
static val REQUEST_TYPE_NONE: Int
```

Keys are already loaded and are available for use. No license request is necessary, and no key request data is returned.  

    Value: 3

### REQUEST_TYPE_RELEASE

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

```
static val REQUEST_TYPE_RELEASE: Int
```

Key request type is license release  

    Value: 2

### REQUEST_TYPE_RENEWAL

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

```
static val REQUEST_TYPE_RENEWAL: Int
```

Key request type is license renewal. A license request is necessary to prevent the keys from expiring.  

    Value: 1

### REQUEST_TYPE_UPDATE

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

```
static val REQUEST_TYPE_UPDATE: Int
```

Keys have been loaded but an additional license request is needed to update their values.  

    Value: 4

## Public methods

### getData

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

```
fun getData(): ByteArray
```

Get the opaque message data

|                                                        Return                                                        ||
|-----------------------------------------------------------------------------------------|-----------------------------|
| [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html) | This value cannot be`null`. |

### getDefaultUrl

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

```
fun getDefaultUrl(): String
```

Get the default URL to use when sending the key request message to a server, if known. The app may prefer to use a different license server URL from other sources. This method returns an empty string if the default URL is not known.

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

### getRequestType

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

```
fun getRequestType(): Int
```

Get the type of the request

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Return                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ||
|----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | Value is[android.media.MediaDrm.KeyRequest#REQUEST_TYPE_INITIAL](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_INITIAL:kotlin.Int),[android.media.MediaDrm.KeyRequest#REQUEST_TYPE_RENEWAL](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_RENEWAL:kotlin.Int),[android.media.MediaDrm.KeyRequest#REQUEST_TYPE_RELEASE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_RELEASE:kotlin.Int),[android.media.MediaDrm.KeyRequest#REQUEST_TYPE_NONE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_NONE:kotlin.Int), or[android.media.MediaDrm.KeyRequest#REQUEST_TYPE_UPDATE](https://developer.android.com/reference/kotlin/android/media/MediaDrm.KeyRequest#REQUEST_TYPE_UPDATE:kotlin.Int) |