Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/media/AudioRecord#nestedclasses) \| [Constants](https://developer.android.com/reference/android/media/AudioRecord#constants) \| [Inherited Constants](https://developer.android.com/reference/android/media/AudioRecord#inhconstants) \| [Ctors](https://developer.android.com/reference/android/media/AudioRecord#pubctors) \| [Methods](https://developer.android.com/reference/android/media/AudioRecord#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/media/AudioRecord#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/AudioRecord#inhmethods)

# AudioRecord

*** ** * ** ***


`
public


class
AudioRecord
`


`

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


`

`


implements

https://developer.android.com/reference/android/media/AudioRecordingMonitor,

https://developer.android.com/reference/android/media/AudioRouting,

https://developer.android.com/reference/android/media/MicrophoneDirection


`

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

<br />

*** ** * ** ***

The AudioRecord class manages the audio resources for Java applications
to record audio from the audio input hardware of the platform. This is
achieved by "pulling" (reading) the data from the AudioRecord object. The
application is responsible for polling the AudioRecord object in time using one of
the following three methods: `https://developer.android.com/reference/android/media/AudioRecord#read(byte[],%20int,%20int)`, `https://developer.android.com/reference/android/media/AudioRecord#read(short[],%20int,%20int)`
or `https://developer.android.com/reference/android/media/AudioRecord#read(java.nio.ByteBuffer,%20int)`. The choice of which method to use will be based
on the audio data storage format that is the most convenient for the user of AudioRecord.

Upon creation, an AudioRecord object initializes its associated audio buffer that it will
fill with the new audio data. The size of this buffer, specified during the construction,
determines how long an AudioRecord can record before "over-running" data that has not
been read yet. Data should be read from the audio hardware in chunks of sizes inferior to
the total recording buffer size.


Applications creating an AudioRecord instance need
`https://developer.android.com/reference/android/Manifest.permission#RECORD_AUDIO` or the Builder will throw
`https://developer.android.com/reference/java/lang/UnsupportedOperationException` on
`https://developer.android.com/reference/android/media/AudioRecord.Builder#build()`,
and the constructor will return an instance in state
`https://developer.android.com/reference/android/media/AudioRecord#STATE_UNINITIALIZED`.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/media/AudioRecord.Builder` Builder class for `https://developer.android.com/reference/android/media/AudioRecord` objects. |
| ` class` | `https://developer.android.com/reference/android/media/AudioRecord.MetricsConstants` |
| ` interface` | `https://developer.android.com/reference/android/media/AudioRecord.OnRecordPositionUpdateListener` Interface definition for a callback to be invoked when an AudioRecord has reached a notification marker set by `https://developer.android.com/reference/android/media/AudioRecord#setNotificationMarkerPosition(int)` or for periodic updates on the progress of the record head, as set by `https://developer.android.com/reference/android/media/AudioRecord#setPositionNotificationPeriod(int)`. |
| ` interface` | `https://developer.android.com/reference/android/media/AudioRecord.OnRoutingChangedListener` *This interface was deprecated in API level 24. users should switch to the general purpose `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` class instead.* |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#ERROR` Denotes a generic operation failure. |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE` Denotes a failure due to the use of an invalid value. |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#ERROR_DEAD_OBJECT` An error code indicating that the object reporting it is no longer valid and needs to be recreated. |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` Denotes a failure due to the improper use of a method. |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING` The read mode indicating the read operation will block until all data requested has been read. |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING` The read mode indicating the read operation will return immediately after reading as much audio data as possible without blocking. |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#RECORDSTATE_RECORDING` indicates AudioRecord recording state is recording |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#RECORDSTATE_STOPPED` indicates AudioRecord recording state is not recording |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#STATE_INITIALIZED` indicates AudioRecord state is ready to be used |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#STATE_UNINITIALIZED` indicates AudioRecord state is not successfully initialized. |
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#SUCCESS` Denotes a successful operation. |

| ### Inherited constants |
|---|
| From interface `https://developer.android.com/reference/android/media/MicrophoneDirection` |---|---| | `int` | `https://developer.android.com/reference/android/media/MicrophoneDirection#MIC_DIRECTION_AWAY_FROM_USER` Optimize capture for audio coming from the side of the device pointing away from the user. | | `int` | `https://developer.android.com/reference/android/media/MicrophoneDirection#MIC_DIRECTION_EXTERNAL` Optimize capture for audio coming from an off-device microphone. | | `int` | `https://developer.android.com/reference/android/media/MicrophoneDirection#MIC_DIRECTION_TOWARDS_USER` Optimize capture for audio coming from the side of the device facing the user. | | `int` | `https://developer.android.com/reference/android/media/MicrophoneDirection#MIC_DIRECTION_UNSPECIFIED` Don't do any directionality processing of the activated microphone(s). | |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/AudioRecord#AudioRecord(int,%20int,%20int,%20int,%20int)(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes) ` Class constructor. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#addOnRoutingChangedListener(android.media.AudioRecord.OnRoutingChangedListener,%20android.os.Handler)(https://developer.android.com/reference/android/media/AudioRecord.OnRoutingChangedListener listener, https://developer.android.com/reference/android/os/Handler handler) ` *This method was deprecated in API level 24. users should switch to the general purpose `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` class instead.* |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#addOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener,%20android.os.Handler)(https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener listener, https://developer.android.com/reference/android/os/Handler handler) ` Adds an `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` to receive notifications of routing changes on this AudioRecord. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MicrophoneInfo>` | ` https://developer.android.com/reference/android/media/AudioRecord#getActiveMicrophones()() ` Returns a lists of `https://developer.android.com/reference/android/media/MicrophoneInfo` representing the active microphones. |
| ` https://developer.android.com/reference/android/media/AudioRecordingConfiguration` | ` https://developer.android.com/reference/android/media/AudioRecord#getActiveRecordingConfiguration()() ` Returns the current active audio recording for this audio recorder. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getAudioFormat()() ` Returns the configured audio data encoding. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getAudioSessionId()() ` Returns the audio session ID. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getAudioSource()() ` Returns the audio recording source. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getBufferSizeInFrames()() ` Returns the frame count of the native `AudioRecord` buffer. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getChannelConfiguration()() ` Returns the configured channel position mask. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getChannelCount()() ` Returns the configured number of channels. |
| ` https://developer.android.com/reference/android/media/AudioFormat` | ` https://developer.android.com/reference/android/media/AudioRecord#getFormat()() ` Returns the configured `AudioRecord` format. |
| ` https://developer.android.com/reference/android/media/metrics/LogSessionId` | ` https://developer.android.com/reference/android/media/AudioRecord#getLogSessionId()() ` Returns the `https://developer.android.com/reference/android/media/metrics/LogSessionId`. |
| ` https://developer.android.com/reference/android/os/PersistableBundle` | ` https://developer.android.com/reference/android/media/AudioRecord#getMetrics()() ` Return Metrics data about the current AudioTrack instance. |
| ` static int` | ` https://developer.android.com/reference/android/media/AudioRecord#getMinBufferSize(int,%20int,%20int)(int sampleRateInHz, int channelConfig, int audioFormat) ` Returns the minimum buffer size required for the successful creation of an AudioRecord object, in byte units. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getNotificationMarkerPosition()() ` Returns the notification marker position expressed in frames. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getPositionNotificationPeriod()() ` Returns the notification update period expressed in frames. |
| ` https://developer.android.com/reference/android/media/AudioDeviceInfo` | ` https://developer.android.com/reference/android/media/AudioRecord#getPreferredDevice()() ` Returns the selected input specified by `https://developer.android.com/reference/android/media/AudioRecord#setPreferredDevice(android.media.AudioDeviceInfo)`. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getRecordingState()() ` Returns the recording state of the AudioRecord instance. |
| ` https://developer.android.com/reference/android/media/AudioDeviceInfo` | ` https://developer.android.com/reference/android/media/AudioRecord#getRoutedDevice()() ` Returns an `https://developer.android.com/reference/android/media/AudioDeviceInfo` identifying the current routing of this AudioRecord. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/AudioDeviceInfo>` | ` https://developer.android.com/reference/android/media/AudioRecord#getRoutedDevices()() ` Returns a List of `https://developer.android.com/reference/android/media/AudioDeviceInfo` identifying the current routing of this AudioRecord. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getSampleRate()() ` Returns the configured audio sink sample rate in Hz. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getState()() ` Returns the state of the AudioRecord instance. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#getTimestamp(android.media.AudioTimestamp,%20int)(https://developer.android.com/reference/android/media/AudioTimestamp outTimestamp, int timebase) ` Poll for an `https://developer.android.com/reference/android/media/AudioTimestamp` on demand. |
| ` boolean` | ` https://developer.android.com/reference/android/media/AudioRecord#isPrivacySensitive()() ` Returns whether this AudioRecord is marked as privacy sensitive or not. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#read(short[],%20int,%20int,%20int)(short[] audioData, int offsetInShorts, int sizeInShorts, int readMode) ` Reads audio data from the audio hardware for recording into a short array. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#read(java.nio.ByteBuffer,%20int,%20int)(https://developer.android.com/reference/java/nio/ByteBuffer audioBuffer, int sizeInBytes, int readMode) ` Reads audio data from the audio hardware for recording into a direct buffer. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#read(short[],%20int,%20int)(short[] audioData, int offsetInShorts, int sizeInShorts) ` Reads audio data from the audio hardware for recording into a short array. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#read(float[],%20int,%20int,%20int)(float[] audioData, int offsetInFloats, int sizeInFloats, int readMode) ` Reads audio data from the audio hardware for recording into a float array. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#read(byte[],%20int,%20int,%20int)(byte[] audioData, int offsetInBytes, int sizeInBytes, int readMode) ` Reads audio data from the audio hardware for recording into a byte array. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#read(java.nio.ByteBuffer,%20int)(https://developer.android.com/reference/java/nio/ByteBuffer audioBuffer, int sizeInBytes) ` Reads audio data from the audio hardware for recording into a direct buffer. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#read(byte[],%20int,%20int)(byte[] audioData, int offsetInBytes, int sizeInBytes) ` Reads audio data from the audio hardware for recording into a byte array. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#registerAudioRecordingCallback(java.util.concurrent.Executor,%20android.media.AudioManager.AudioRecordingCallback)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/media/AudioManager.AudioRecordingCallback cb) ` Register a callback to be notified of audio capture changes via a `https://developer.android.com/reference/android/media/AudioManager.AudioRecordingCallback`. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#release()() ` Releases the native AudioRecord resources. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#removeOnRoutingChangedListener(android.media.AudioRecord.OnRoutingChangedListener)(https://developer.android.com/reference/android/media/AudioRecord.OnRoutingChangedListener listener) ` *This method was deprecated in API level 24. users should switch to the general purpose `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` class instead.* |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#removeOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener)(https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener listener) ` Removes an `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` which has been previously added to receive rerouting notifications. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#setLogSessionId(android.media.metrics.LogSessionId)(https://developer.android.com/reference/android/media/metrics/LogSessionId logSessionId) ` Sets a `https://developer.android.com/reference/android/media/metrics/LogSessionId` instance to this AudioRecord for metrics collection. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#setNotificationMarkerPosition(int)(int markerInFrames) ` Sets the marker position at which the listener is called, if set with `https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener)` or `https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener,%20android.os.Handler)`. |
| ` int` | ` https://developer.android.com/reference/android/media/AudioRecord#setPositionNotificationPeriod(int)(int periodInFrames) ` Sets the period at which the listener is called, if set with `https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener)` or `https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener,%20android.os.Handler)`. |
| ` boolean` | ` https://developer.android.com/reference/android/media/AudioRecord#setPreferredDevice(android.media.AudioDeviceInfo)(https://developer.android.com/reference/android/media/AudioDeviceInfo deviceInfo) ` Specifies an audio device (via an `https://developer.android.com/reference/android/media/AudioDeviceInfo` object) to route the input to this AudioRecord. |
| ` boolean` | ` https://developer.android.com/reference/android/media/AudioRecord#setPreferredMicrophoneDirection(int)(int direction) ` Specifies the logical microphone (for processing). |
| ` boolean` | ` https://developer.android.com/reference/android/media/AudioRecord#setPreferredMicrophoneFieldDimension(float)(float zoom) ` Specifies the zoom factor (i.e. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener)(https://developer.android.com/reference/android/media/AudioRecord.OnRecordPositionUpdateListener listener) ` Sets the listener the AudioRecord notifies when a previously set marker is reached or for each periodic record head position update. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener,%20android.os.Handler)(https://developer.android.com/reference/android/media/AudioRecord.OnRecordPositionUpdateListener listener, https://developer.android.com/reference/android/os/Handler handler) ` Sets the listener the AudioRecord notifies when a previously set marker is reached or for each periodic record head position update. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#startRecording(android.media.MediaSyncEvent)(https://developer.android.com/reference/android/media/MediaSyncEvent syncEvent) ` Starts recording from the AudioRecord instance when the specified synchronization event occurs on the specified audio session. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#startRecording()() ` Starts recording from the AudioRecord instance. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#stop()() ` Stops recording. |
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#unregisterAudioRecordingCallback(android.media.AudioManager.AudioRecordingCallback)(https://developer.android.com/reference/android/media/AudioManager.AudioRecordingCallback cb) ` Unregister an audio recording callback previously registered with `https://developer.android.com/reference/android/media/AudioRecord#registerAudioRecordingCallback(java.util.concurrent.Executor,%20android.media.AudioManager.AudioRecordingCallback)`. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/AudioRecord#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

| ### 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/media/AudioRecordingMonitor ` |---|---| | ` abstract https://developer.android.com/reference/android/media/AudioRecordingConfiguration` | ` https://developer.android.com/reference/android/media/AudioRecordingMonitor#getActiveRecordingConfiguration()() ` Returns the current active audio recording for this audio recorder. | | ` abstract void` | ` https://developer.android.com/reference/android/media/AudioRecordingMonitor#registerAudioRecordingCallback(java.util.concurrent.Executor,%20android.media.AudioManager.AudioRecordingCallback)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/media/AudioManager.AudioRecordingCallback cb) ` Register a callback to be notified of audio capture changes via a `https://developer.android.com/reference/android/media/AudioManager.AudioRecordingCallback`. | | ` abstract void` | ` https://developer.android.com/reference/android/media/AudioRecordingMonitor#unregisterAudioRecordingCallback(android.media.AudioManager.AudioRecordingCallback)(https://developer.android.com/reference/android/media/AudioManager.AudioRecordingCallback cb) ` Unregister an audio recording callback previously registered with `https://developer.android.com/reference/android/media/AudioRecordingMonitor#registerAudioRecordingCallback(java.util.concurrent.Executor,%20android.media.AudioManager.AudioRecordingCallback)`. | ||
| From interface ` https://developer.android.com/reference/android/media/AudioRouting ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/android/media/AudioRouting#addOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener,%20android.os.Handler)(https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener listener, https://developer.android.com/reference/android/os/Handler handler) ` Adds an `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` to receive notifications of routing changes on this AudioTrack/AudioRecord. | | ` abstract https://developer.android.com/reference/android/media/AudioDeviceInfo` | ` https://developer.android.com/reference/android/media/AudioRouting#getPreferredDevice()() ` Returns the selected output/input specified by `https://developer.android.com/reference/android/media/AudioRouting#setPreferredDevice(android.media.AudioDeviceInfo)`. | | ` abstract https://developer.android.com/reference/android/media/AudioDeviceInfo` | ` https://developer.android.com/reference/android/media/AudioRouting#getRoutedDevice()() ` Returns an `https://developer.android.com/reference/android/media/AudioDeviceInfo` identifying the current routing of this AudioTrack/AudioRecord. | | ` default https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/AudioDeviceInfo>` | ` https://developer.android.com/reference/android/media/AudioRouting#getRoutedDevices()() ` Returns a List of `https://developer.android.com/reference/android/media/AudioDeviceInfo` identifying the current routing of this AudioTrack/AudioRecord. | | ` abstract void` | ` https://developer.android.com/reference/android/media/AudioRouting#removeOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener)(https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener listener) ` Removes an `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` which has been previously added to receive rerouting notifications. | | ` abstract boolean` | ` https://developer.android.com/reference/android/media/AudioRouting#setPreferredDevice(android.media.AudioDeviceInfo)(https://developer.android.com/reference/android/media/AudioDeviceInfo deviceInfo) ` Specifies an audio device (via an `https://developer.android.com/reference/android/media/AudioDeviceInfo` object) to route the output/input to/from. | ||
| From interface ` https://developer.android.com/reference/android/media/MicrophoneDirection ` |---|---| | ` abstract boolean` | ` https://developer.android.com/reference/android/media/MicrophoneDirection#setPreferredMicrophoneDirection(int)(int direction) ` Specifies the logical microphone (for processing). | | ` abstract boolean` | ` https://developer.android.com/reference/android/media/MicrophoneDirection#setPreferredMicrophoneFieldDimension(float)(float zoom) ` Specifies the zoom factor (i.e. | ||

## Constants

### ERROR

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

```
public static final int ERROR
```

Denotes a generic operation failure.

<br />

Constant Value:

-1
(0xffffffff)


### ERROR_BAD_VALUE

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

```
public static final int ERROR_BAD_VALUE
```

Denotes a failure due to the use of an invalid value.

<br />

Constant Value:

-2
(0xfffffffe)


### ERROR_DEAD_OBJECT

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

```
public static final int ERROR_DEAD_OBJECT
```

An error code indicating that the object reporting it is no longer valid and needs to
be recreated.

<br />

Constant Value:

-6
(0xfffffffa)


### ERROR_INVALID_OPERATION

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

```
public static final int ERROR_INVALID_OPERATION
```

Denotes a failure due to the improper use of a method.

<br />

Constant Value:

-3
(0xfffffffd)


### READ_BLOCKING

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

```
public static final int READ_BLOCKING
```

The read mode indicating the read operation will block until all data
requested has been read.

<br />

Constant Value:

0
(0x00000000)


### READ_NON_BLOCKING

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

```
public static final int READ_NON_BLOCKING
```

The read mode indicating the read operation will return immediately after
reading as much audio data as possible without blocking.

<br />

Constant Value:

1
(0x00000001)


### RECORDSTATE_RECORDING

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

```
public static final int RECORDSTATE_RECORDING
```

indicates AudioRecord recording state is recording

<br />

Constant Value:

3
(0x00000003)


### RECORDSTATE_STOPPED

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

```
public static final int RECORDSTATE_STOPPED
```

indicates AudioRecord recording state is not recording

<br />

Constant Value:

1
(0x00000001)


### STATE_INITIALIZED

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

```
public static final int STATE_INITIALIZED
```

indicates AudioRecord state is ready to be used

<br />

Constant Value:

1
(0x00000001)


### STATE_UNINITIALIZED

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

```
public static final int STATE_UNINITIALIZED
```

indicates AudioRecord state is not successfully initialized.

<br />

Constant Value:

0
(0x00000000)


### SUCCESS

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

```
public static final int SUCCESS
```

Denotes a successful operation.

<br />

Constant Value:

0
(0x00000000)


## Public constructors

### AudioRecord

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

```
public AudioRecord (int audioSource, 
                int sampleRateInHz, 
                int channelConfig, 
                int audioFormat, 
                int bufferSizeInBytes)
```

Class constructor.
Though some invalid parameters will result in an `https://developer.android.com/reference/java/lang/IllegalArgumentException` exception,
other errors do not. Thus you should call `https://developer.android.com/reference/android/media/AudioRecord#getState()` immediately after construction
to confirm that the object is usable.


Requires `https://developer.android.com/reference/android/Manifest.permission#RECORD_AUDIO`

<br />

| Parameters ||
|---|---|
| `audioSource` | `int`: the recording source. See `https://developer.android.com/reference/android/media/MediaRecorder.AudioSource` for the recording source definitions. <br /> |
| `sampleRateInHz` | `int`: the sample rate expressed in Hertz. 44100Hz is currently the only rate that is guaranteed to work on all devices, but other rates such as 22050, 16000, and 11025 may work on some devices. `https://developer.android.com/reference/android/media/AudioFormat#SAMPLE_RATE_UNSPECIFIED` means to use a route-dependent value which is usually the sample rate of the source. `https://developer.android.com/reference/android/media/AudioRecord#getSampleRate()` can be used to retrieve the actual sample rate chosen. <br /> |
| `channelConfig` | `int`: describes the configuration of the audio channels. See `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_IN_MONO` and `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_IN_STEREO`. `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_IN_MONO` is guaranteed to work on all devices. <br /> |
| `audioFormat` | `int`: the format in which the audio data is to be returned. See `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_8BIT`, `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_16BIT`, and `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_FLOAT`. <br /> |
| `bufferSizeInBytes` | `int`: the total size (in bytes) of the buffer where audio data is written to during the recording. New audio data can be read from this buffer in smaller chunks than this size. See `https://developer.android.com/reference/android/media/AudioRecord#getMinBufferSize(int,%20int,%20int)` to determine the minimum required buffer size for the successful creation of an AudioRecord instance. Using values smaller than getMinBufferSize() will result in an initialization failure. <br /> |

| Throws ||
|---|---|
|   | java.lang.IllegalArgumentException |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` |   |

## Public methods

### addOnRoutingChangedListener

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

```
public void addOnRoutingChangedListener (AudioRecord.OnRoutingChangedListener listener, 
                Handler handler)
```


**This method was deprecated
in API level 24.**   

users should switch to the general purpose
`https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` class instead.

Adds an `https://developer.android.com/reference/android/media/AudioRecord.OnRoutingChangedListener` to receive notifications of routing changes
on this AudioRecord.

<br />

| Parameters ||
|---|---|
| `listener` | `AudioRecord.OnRoutingChangedListener`: The `https://developer.android.com/reference/android/media/AudioRecord.OnRoutingChangedListener` interface to receive notifications of rerouting events. <br /> |
| `handler` | `Handler`: Specifies the `https://developer.android.com/reference/android/os/Handler` object for the thread on which to execute the callback. If `null`, the `https://developer.android.com/reference/android/os/Handler` associated with the main `https://developer.android.com/reference/android/os/Looper` will be used. <br /> |

### addOnRoutingChangedListener

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

```
public void addOnRoutingChangedListener (AudioRouting.OnRoutingChangedListener listener, 
                Handler handler)
```

Adds an `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` to receive notifications of
routing changes on this AudioRecord.

<br />

| Parameters ||
|---|---|
| `listener` | `AudioRouting.OnRoutingChangedListener`: The `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` interface to receive notifications of rerouting events. <br /> |
| `handler` | `Handler`: Specifies the `https://developer.android.com/reference/android/os/Handler` object for the thread on which to execute the callback. If `null`, the `https://developer.android.com/reference/android/os/Handler` associated with the main `https://developer.android.com/reference/android/os/Looper` will be used. <br /> |

### getActiveMicrophones

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

```
public List<MicrophoneInfo> getActiveMicrophones ()
```

Returns a lists of `https://developer.android.com/reference/android/media/MicrophoneInfo` representing the active microphones.
By querying channel mapping for each active microphone, developer can know how
the microphone is used by each channels or a capture stream.
Note that the information about the active microphones may change during a recording.
See `https://developer.android.com/reference/android/media/AudioManager#registerAudioDeviceCallback(android.media.AudioDeviceCallback,%20android.os.Handler)` to be notified of changes
in the audio devices, querying the active microphones then will return the latest
information.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/MicrophoneInfo>` | a lists of `https://developer.android.com/reference/android/media/MicrophoneInfo` representing the active microphones. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an error occurs |

### getActiveRecordingConfiguration

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

```
public AudioRecordingConfiguration getActiveRecordingConfiguration ()
```

Returns the current active audio recording for this audio recorder.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/AudioRecordingConfiguration` | a valid `https://developer.android.com/reference/android/media/AudioRecordingConfiguration` if this recorder is active or null otherwise. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/AudioRecordingConfiguration`

### getAudioFormat

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

```
public int getAudioFormat ()
```

Returns the configured audio data encoding. See `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_8BIT`,
`https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_16BIT`, and `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_FLOAT`.

<br />

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

### getAudioSessionId

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

```
public int getAudioSessionId ()
```

Returns the audio session ID.

<br />

| Returns ||
|---|---|
| `int` | the ID of the audio session this AudioRecord belongs to. <br /> |

### getAudioSource

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

```
public int getAudioSource ()
```

Returns the audio recording source.

<br />

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

**See also:**

- `https://developer.android.com/reference/android/media/MediaRecorder.AudioSource`

### getBufferSizeInFrames

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

```
public int getBufferSizeInFrames ()
```

Returns the frame count of the native `AudioRecord` buffer.
This is greater than or equal to the bufferSizeInBytes converted to frame units
specified in the `AudioRecord` constructor or Builder.
The native frame count may be enlarged to accommodate the requirements of the
source on creation or if the `AudioRecord`
is subsequently rerouted.

<br />

| Returns ||
|---|---|
| `int` | current size in frames of the `AudioRecord` buffer. <br /> |

| Throws ||
|---|---|
|   | java.lang.IllegalStateException |

### getChannelConfiguration

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

```
public int getChannelConfiguration ()
```

Returns the configured channel position mask.

See `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_IN_MONO`
and `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_IN_STEREO`.
This method may return `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_INVALID` if
a channel index mask is used.
Consider `https://developer.android.com/reference/android/media/AudioRecord#getFormat()` instead, to obtain an `https://developer.android.com/reference/android/media/AudioFormat`,
which contains both the channel position mask and the channel index mask.

<br />

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

### getChannelCount

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

```
public int getChannelCount ()
```

Returns the configured number of channels.

<br />

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

### getFormat

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

```
public AudioFormat getFormat ()
```

Returns the configured `AudioRecord` format.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/AudioFormat` | an `https://developer.android.com/reference/android/media/AudioFormat` containing the `AudioRecord` parameters at the time of configuration. This value cannot be `null`. <br /> |

### getLogSessionId

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

```
public LogSessionId getLogSessionId ()
```

Returns the `https://developer.android.com/reference/android/media/metrics/LogSessionId`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/metrics/LogSessionId` | This value cannot be `null`. <br /> |

### getMetrics

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

```
public PersistableBundle getMetrics ()
```

Return Metrics data about the current AudioTrack instance.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/PersistableBundle` | a `https://developer.android.com/reference/android/os/PersistableBundle` containing the set of attributes and values available for the media being handled by this instance of AudioRecord The attributes are descibed in `https://developer.android.com/reference/android/media/AudioRecord.MetricsConstants`. Additional vendor-specific fields may also be present in the return value. <br /> |

### getMinBufferSize

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

```
public static int getMinBufferSize (int sampleRateInHz, 
                int channelConfig, 
                int audioFormat)
```

Returns the minimum buffer size required for the successful creation of an AudioRecord
object, in byte units.
Note that this size doesn't guarantee a smooth recording under load, and higher values
should be chosen according to the expected frequency at which the AudioRecord instance
will be polled for new data.
See `https://developer.android.com/reference/android/media/AudioRecord#AudioRecord(int,%20int,%20int,%20int,%20int)` for more information on valid
configuration values.

<br />

| Parameters ||
|---|---|
| `sampleRateInHz` | `int`: the sample rate expressed in Hertz. `https://developer.android.com/reference/android/media/AudioFormat#SAMPLE_RATE_UNSPECIFIED` is not permitted. <br /> |
| `channelConfig` | `int`: describes the configuration of the audio channels. See `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_IN_MONO` and `https://developer.android.com/reference/android/media/AudioFormat#CHANNEL_IN_STEREO` <br /> |
| `audioFormat` | `int`: the format in which the audio data is represented. See `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_16BIT`. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE` if the recording parameters are not supported by the hardware, or an invalid parameter was passed, or `https://developer.android.com/reference/android/media/AudioRecord#ERROR` if the implementation was unable to query the hardware for its input properties, or the minimum buffer size expressed in bytes. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/AudioRecord#AudioRecord(int,%20int,%20int,%20int,%20int)`

### getNotificationMarkerPosition

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

```
public int getNotificationMarkerPosition ()
```

Returns the notification marker position expressed in frames.

<br />

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

### getPositionNotificationPeriod

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

```
public int getPositionNotificationPeriod ()
```

Returns the notification update period expressed in frames.

<br />

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

### getPreferredDevice

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

```
public AudioDeviceInfo getPreferredDevice ()
```

Returns the selected input specified by `https://developer.android.com/reference/android/media/AudioRecord#setPreferredDevice(android.media.AudioDeviceInfo)`. Note that this
is not guarenteed to correspond to the actual device being used for recording.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/AudioDeviceInfo` | <br /> |

### getRecordingState

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

```
public int getRecordingState ()
```

Returns the recording state of the AudioRecord instance.

<br />

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

**See also:**

- `https://developer.android.com/reference/android/media/AudioRecord#RECORDSTATE_STOPPED`
- `https://developer.android.com/reference/android/media/AudioRecord#RECORDSTATE_RECORDING`

### getRoutedDevice

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

```
public AudioDeviceInfo getRoutedDevice ()
```

Returns an `https://developer.android.com/reference/android/media/AudioDeviceInfo` identifying the current routing of this AudioRecord.
Note: The query is only valid if the AudioRecord is currently recording. If it is not,
`getRoutedDevice()` will return null.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/media/AudioDeviceInfo` | <br /> |

### getRoutedDevices

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

```
public List<AudioDeviceInfo> getRoutedDevices ()
```

Returns a List of `https://developer.android.com/reference/android/media/AudioDeviceInfo` identifying the current routing of this
AudioRecord.
Note: The query is only valid if the AudioRecord is currently playing. If it is not,
`getRoutedDevices()` will return an empty list.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/media/AudioDeviceInfo>` | This value cannot be `null`. <br /> |

### getSampleRate

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

```
public int getSampleRate ()
```

Returns the configured audio sink sample rate in Hz.
The sink sample rate never changes after construction.
If the constructor had a specific sample rate, then the sink sample rate is that value.
If the constructor had `https://developer.android.com/reference/android/media/AudioFormat#SAMPLE_RATE_UNSPECIFIED`,
then the sink sample rate is a route-dependent default value based on the source \[sic\].

<br />

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

### getState

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

```
public int getState ()
```

Returns the state of the AudioRecord instance. This is useful after the
AudioRecord instance has been created to check if it was initialized
properly. This ensures that the appropriate hardware resources have been
acquired.

<br />

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

**See also:**

- `https://developer.android.com/reference/android/media/AudioRecord#STATE_INITIALIZED`
- `https://developer.android.com/reference/android/media/AudioRecord#STATE_UNINITIALIZED`

### getTimestamp

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

```
public int getTimestamp (AudioTimestamp outTimestamp, 
                int timebase)
```

Poll for an `https://developer.android.com/reference/android/media/AudioTimestamp` on demand.


The AudioTimestamp reflects the frame delivery information at
the earliest point available in the capture pipeline.


Calling `https://developer.android.com/reference/android/media/AudioRecord#startRecording()` following a `https://developer.android.com/reference/android/media/AudioRecord#stop()` will reset
the frame count to 0.

<br />

| Parameters ||
|---|---|
| `outTimestamp` | `AudioTimestamp`: a caller provided non-null AudioTimestamp instance, which is updated with the AudioRecord frame delivery information upon success. <br /> |
| `timebase` | `int`: one of `https://developer.android.com/reference/android/media/AudioTimestamp#TIMEBASE_BOOTTIME` or `https://developer.android.com/reference/android/media/AudioTimestamp#TIMEBASE_MONOTONIC`, used to select the clock for the AudioTimestamp time. Value is one of the following: - `https://developer.android.com/reference/android/media/AudioTimestamp#TIMEBASE_MONOTONIC` - `https://developer.android.com/reference/android/media/AudioTimestamp#TIMEBASE_BOOTTIME` |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/media/AudioRecord#SUCCESS` if a timestamp is available, or `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` if a timestamp not available. <br /> |

### isPrivacySensitive

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

```
public boolean isPrivacySensitive ()
```

Returns whether this AudioRecord is marked as privacy sensitive or not.


See `https://developer.android.com/reference/android/media/AudioRecord.Builder#setPrivacySensitive(boolean)`

<br />

<br />

| Returns ||
|---|---|
| `boolean` | true if privacy sensitive, false otherwise <br /> |

### read

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

```
public int read (short[] audioData, 
                int offsetInShorts, 
                int sizeInShorts, 
                int readMode)
```

Reads audio data from the audio hardware for recording into a short array.
The format specified in the AudioRecord constructor should be
`https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_16BIT` to correspond to the data in the array.

<br />

| Parameters ||
|---|---|
| `audioData` | `short`: the array to which the recorded audio data is written. This value cannot be `null`. <br /> |
| `offsetInShorts` | `int`: index in audioData from which the data is written expressed in shorts. Must not be negative, or cause the data access to go out of bounds of the array. <br /> |
| `sizeInShorts` | `int`: the number of requested shorts. Must not be negative, or cause the data access to go out of bounds of the array. <br /> |
| `readMode` | `int`: one of `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING`, `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING`. With `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING`, the read will block until all the requested data is read. With `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING`, the read will return immediately after reading as much audio data as possible without blocking. Value is one of the following: - `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING` - `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING` |

| Returns ||
|---|---|
| `int` | zero or the positive number of shorts that were read, or one of the following error codes. The number of shorts will be a multiple of the channel count not to exceed sizeInShorts. - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` if the object isn't properly initialized - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE` if the parameters don't resolve to valid data and indexes - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_DEAD_OBJECT` if the object is not valid anymore and needs to be recreated. The dead object error code is not returned if some data was successfully transferred. In this case, the error is returned at the next read() - `https://developer.android.com/reference/android/media/AudioRecord#ERROR` in case of other error <br /> |

### read

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

```
public int read (ByteBuffer audioBuffer, 
                int sizeInBytes, 
                int readMode)
```

Reads audio data from the audio hardware for recording into a direct buffer. If this buffer
is not a direct buffer, this method will always return 0.
Note that the value returned by `https://developer.android.com/reference/java/nio/Buffer#position()` on this buffer is
unchanged after a call to this method.
The representation of the data in the buffer will depend on the format specified in
the AudioRecord constructor, and will be native endian.

<br />

| Parameters ||
|---|---|
| `audioBuffer` | `ByteBuffer`: the direct buffer to which the recorded audio data is written. Data is written to the beginning of the byte buffer. Importantly, this method ignores the `https://developer.android.com/reference/java/nio/Buffer#position()` and `https://developer.android.com/reference/java/nio/Buffer#limit()` properties. This value cannot be `null`. <br /> |
| `sizeInBytes` | `int`: the number of requested bytes. It is recommended but not enforced that the number of bytes requested be a multiple of the frame size (sample size in bytes multiplied by the channel count). <br /> |
| `readMode` | `int`: one of `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING`, `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING`. With `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING`, the read will block until all the requested data is read. With `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING`, the read will return immediately after reading as much audio data as possible without blocking. Value is one of the following: - `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING` - `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING` |

| Returns ||
|---|---|
| `int` | zero or the positive number of bytes that were read, or one of the following error codes. The number of bytes will not exceed sizeInBytes and will be truncated to be a multiple of the frame size. - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` if the object isn't properly initialized - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE` if the parameters don't resolve to valid data and indexes - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_DEAD_OBJECT` if the object is not valid anymore and needs to be recreated. The dead object error code is not returned if some data was successfully transferred. In this case, the error is returned at the next read() - `https://developer.android.com/reference/android/media/AudioRecord#ERROR` in case of other error <br /> |

### read

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

```
public int read (short[] audioData, 
                int offsetInShorts, 
                int sizeInShorts)
```

Reads audio data from the audio hardware for recording into a short array.
The format specified in the AudioRecord constructor should be
`https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_16BIT` to correspond to the data in the array.

<br />

| Parameters ||
|---|---|
| `audioData` | `short`: the array to which the recorded audio data is written. This value cannot be `null`. <br /> |
| `offsetInShorts` | `int`: index in audioData to which the data is written expressed in shorts. Must not be negative, or cause the data access to go out of bounds of the array. <br /> |
| `sizeInShorts` | `int`: the number of requested shorts. Must not be negative, or cause the data access to go out of bounds of the array. <br /> |

| Returns ||
|---|---|
| `int` | zero or the positive number of shorts that were read, or one of the following error codes. The number of shorts will be a multiple of the channel count not to exceed sizeInShorts. - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` if the object isn't properly initialized - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE` if the parameters don't resolve to valid data and indexes - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_DEAD_OBJECT` if the object is not valid anymore and needs to be recreated. The dead object error code is not returned if some data was successfully transferred. In this case, the error is returned at the next read() - `https://developer.android.com/reference/android/media/AudioRecord#ERROR` in case of other error <br /> |

### read

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

```
public int read (float[] audioData, 
                int offsetInFloats, 
                int sizeInFloats, 
                int readMode)
```

Reads audio data from the audio hardware for recording into a float array.
The format specified in the AudioRecord constructor should be
`https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_FLOAT` to correspond to the data in the array.

<br />

| Parameters ||
|---|---|
| `audioData` | `float`: the array to which the recorded audio data is written. This value cannot be `null`. <br /> |
| `offsetInFloats` | `int`: index in audioData from which the data is written. Must not be negative, or cause the data access to go out of bounds of the array. <br /> |
| `sizeInFloats` | `int`: the number of requested floats. Must not be negative, or cause the data access to go out of bounds of the array. <br /> |
| `readMode` | `int`: one of `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING`, `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING`. With `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING`, the read will block until all the requested data is read. With `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING`, the read will return immediately after reading as much audio data as possible without blocking. Value is one of the following: - `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING` - `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING` |

| Returns ||
|---|---|
| `int` | zero or the positive number of floats that were read, or one of the following error codes. The number of floats will be a multiple of the channel count not to exceed sizeInFloats. - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` if the object isn't properly initialized - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE` if the parameters don't resolve to valid data and indexes - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_DEAD_OBJECT` if the object is not valid anymore and needs to be recreated. The dead object error code is not returned if some data was successfully transferred. In this case, the error is returned at the next read() - `https://developer.android.com/reference/android/media/AudioRecord#ERROR` in case of other error <br /> |

### read

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

```
public int read (byte[] audioData, 
                int offsetInBytes, 
                int sizeInBytes, 
                int readMode)
```

Reads audio data from the audio hardware for recording into a byte array.
The format specified in the AudioRecord constructor should be
`https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_8BIT` to correspond to the data in the array.
The format can be `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_16BIT`, but this is deprecated.

<br />

| Parameters ||
|---|---|
| `audioData` | `byte`: the array to which the recorded audio data is written. This value cannot be `null`. <br /> |
| `offsetInBytes` | `int`: index in audioData to which the data is written expressed in bytes. Must not be negative, or cause the data access to go out of bounds of the array. <br /> |
| `sizeInBytes` | `int`: the number of requested bytes. Must not be negative, or cause the data access to go out of bounds of the array. <br /> |
| `readMode` | `int`: one of `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING`, `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING`. With `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING`, the read will block until all the requested data is read. With `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING`, the read will return immediately after reading as much audio data as possible without blocking. Value is one of the following: - `https://developer.android.com/reference/android/media/AudioRecord#READ_BLOCKING` - `https://developer.android.com/reference/android/media/AudioRecord#READ_NON_BLOCKING` |

| Returns ||
|---|---|
| `int` | zero or the positive number of bytes that were read, or one of the following error codes. The number of bytes will be a multiple of the frame size in bytes not to exceed sizeInBytes. - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` if the object isn't properly initialized - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE` if the parameters don't resolve to valid data and indexes - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_DEAD_OBJECT` if the object is not valid anymore and needs to be recreated. The dead object error code is not returned if some data was successfully transferred. In this case, the error is returned at the next read() - `https://developer.android.com/reference/android/media/AudioRecord#ERROR` in case of other error <br /> |

### read

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

```
public int read (ByteBuffer audioBuffer, 
                int sizeInBytes)
```

Reads audio data from the audio hardware for recording into a direct buffer. If this buffer
is not a direct buffer, this method will always return 0.
Note that the value returned by `https://developer.android.com/reference/java/nio/Buffer#position()` on this buffer is
unchanged after a call to this method.
The representation of the data in the buffer will depend on the format specified in
the AudioRecord constructor, and will be native endian.

<br />

| Parameters ||
|---|---|
| `audioBuffer` | `ByteBuffer`: the direct buffer to which the recorded audio data is written. Data is written to the beginning of the byte buffer. Importantly, this method ignores the `https://developer.android.com/reference/java/nio/Buffer#position()` and `https://developer.android.com/reference/java/nio/Buffer#limit()` properties. This value cannot be `null`. <br /> |
| `sizeInBytes` | `int`: the number of requested bytes. It is recommended but not enforced that the number of bytes requested be a multiple of the frame size (sample size in bytes multiplied by the channel count). <br /> |

| Returns ||
|---|---|
| `int` | zero or the positive number of bytes that were read, or one of the following error codes. The number of bytes will not exceed sizeInBytes and will be truncated to be a multiple of the frame size. - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` if the object isn't properly initialized - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE` if the parameters don't resolve to valid data and indexes - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_DEAD_OBJECT` if the object is not valid anymore and needs to be recreated. The dead object error code is not returned if some data was successfully transferred. In this case, the error is returned at the next read() - `https://developer.android.com/reference/android/media/AudioRecord#ERROR` in case of other error <br /> |

### read

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

```
public int read (byte[] audioData, 
                int offsetInBytes, 
                int sizeInBytes)
```

Reads audio data from the audio hardware for recording into a byte array.
The format specified in the AudioRecord constructor should be
`https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_8BIT` to correspond to the data in the array.

<br />

| Parameters ||
|---|---|
| `audioData` | `byte`: the array to which the recorded audio data is written. This value cannot be `null`. <br /> |
| `offsetInBytes` | `int`: index in audioData from which the data is written expressed in bytes. <br /> |
| `sizeInBytes` | `int`: the number of requested bytes. <br /> |

| Returns ||
|---|---|
| `int` | zero or the positive number of bytes that were read, or one of the following error codes. The number of bytes will not exceed sizeInBytes. - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` if the object isn't properly initialized - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE` if the parameters don't resolve to valid data and indexes - `https://developer.android.com/reference/android/media/AudioRecord#ERROR_DEAD_OBJECT` if the object is not valid anymore and needs to be recreated. The dead object error code is not returned if some data was successfully transferred. In this case, the error is returned at the next read() - `https://developer.android.com/reference/android/media/AudioRecord#ERROR` in case of other error <br /> |

### registerAudioRecordingCallback

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

```
public void registerAudioRecordingCallback (Executor executor, 
                AudioManager.AudioRecordingCallback cb)
```

Register a callback to be notified of audio capture changes via a
`https://developer.android.com/reference/android/media/AudioManager.AudioRecordingCallback`. A callback is received when the capture path
configuration changes (pre-processing, format, sampling rate...) or capture is
silenced/unsilenced by the system.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: `https://developer.android.com/reference/java/util/concurrent/Executor` to handle the callbacks. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `cb` | `AudioManager.AudioRecordingCallback`: non-null callback to register <br /> |

### release

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

```
public void release ()
```

Releases the native AudioRecord resources.
The object can no longer be used and the reference should be set to null
after a call to release()

<br />

### removeOnRoutingChangedListener

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

```
public void removeOnRoutingChangedListener (AudioRecord.OnRoutingChangedListener listener)
```


**This method was deprecated
in API level 24.**   

users should switch to the general purpose
`https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` class instead.

Removes an `https://developer.android.com/reference/android/media/AudioRecord.OnRoutingChangedListener` which has been previously added
to receive rerouting notifications.

<br />

| Parameters ||
|---|---|
| `listener` | `AudioRecord.OnRoutingChangedListener`: The previously added `https://developer.android.com/reference/android/media/AudioRecord.OnRoutingChangedListener` interface to remove. <br /> |

### removeOnRoutingChangedListener

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

```
public void removeOnRoutingChangedListener (AudioRouting.OnRoutingChangedListener listener)
```

Removes an `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` which has been previously added
to receive rerouting notifications.

<br />

| Parameters ||
|---|---|
| `listener` | `AudioRouting.OnRoutingChangedListener`: The previously added `https://developer.android.com/reference/android/media/AudioRouting.OnRoutingChangedListener` interface to remove. <br /> |

### setLogSessionId

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

```
public void setLogSessionId (LogSessionId logSessionId)
```

Sets a `https://developer.android.com/reference/android/media/metrics/LogSessionId` instance to this AudioRecord for metrics collection.

<br />

| Parameters ||
|---|---|
| `logSessionId` | `LogSessionId`: a `https://developer.android.com/reference/android/media/metrics/LogSessionId` instance which is used to identify this object to the metrics service. Proper generated Ids must be obtained from the Java metrics service and should be considered opaque. Use `https://developer.android.com/reference/android/media/metrics/LogSessionId#LOG_SESSION_ID_NONE` to remove the logSessionId association. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if AudioRecord not initialized. |

### setNotificationMarkerPosition

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

```
public int setNotificationMarkerPosition (int markerInFrames)
```

Sets the marker position at which the listener is called, if set with
`https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener)` or
`https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener,%20android.os.Handler)`.

<br />

| Parameters ||
|---|---|
| `markerInFrames` | `int`: marker position expressed in frames <br /> |

| Returns ||
|---|---|
| `int` | error code or success, see `https://developer.android.com/reference/android/media/AudioRecord#SUCCESS`, `https://developer.android.com/reference/android/media/AudioRecord#ERROR_BAD_VALUE`, `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` <br /> |

### setPositionNotificationPeriod

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

```
public int setPositionNotificationPeriod (int periodInFrames)
```

Sets the period at which the listener is called, if set with
`https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener)` or
`https://developer.android.com/reference/android/media/AudioRecord#setRecordPositionUpdateListener(android.media.AudioRecord.OnRecordPositionUpdateListener,%20android.os.Handler)`.
It is possible for notifications to be lost if the period is too small.

<br />

| Parameters ||
|---|---|
| `periodInFrames` | `int`: update period expressed in frames <br /> |

| Returns ||
|---|---|
| `int` | error code or success, see `https://developer.android.com/reference/android/media/AudioRecord#SUCCESS`, `https://developer.android.com/reference/android/media/AudioRecord#ERROR_INVALID_OPERATION` <br /> |

### setPreferredDevice

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

```
public boolean setPreferredDevice (AudioDeviceInfo deviceInfo)
```

Specifies an audio device (via an `https://developer.android.com/reference/android/media/AudioDeviceInfo` object) to route
the input to this AudioRecord.

<br />

| Parameters ||
|---|---|
| `deviceInfo` | `AudioDeviceInfo`: The `https://developer.android.com/reference/android/media/AudioDeviceInfo` specifying the audio source. If deviceInfo is null, default routing is restored. <br /> |

| Returns ||
|---|---|
| `boolean` | true if successful, false if the specified `https://developer.android.com/reference/android/media/AudioDeviceInfo` is non-null and does not correspond to a valid audio input device. <br /> |

### setPreferredMicrophoneDirection

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

```
public boolean setPreferredMicrophoneDirection (int direction)
```

Specifies the logical microphone (for processing). Applications can use this to specify
which side of the device to optimize capture from. Typically used in conjunction with
the camera capturing video.

<br />

| Parameters ||
|---|---|
| `direction` | `int`: Value is one of the following: - `https://developer.android.com/reference/android/media/MicrophoneDirection#MIC_DIRECTION_UNSPECIFIED` - `https://developer.android.com/reference/android/media/MicrophoneDirection#MIC_DIRECTION_TOWARDS_USER` - `https://developer.android.com/reference/android/media/MicrophoneDirection#MIC_DIRECTION_AWAY_FROM_USER` - `https://developer.android.com/reference/android/media/MicrophoneDirection#MIC_DIRECTION_EXTERNAL` |

| Returns ||
|---|---|
| `boolean` | true if sucessful. <br /> |

### setPreferredMicrophoneFieldDimension

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

```
public boolean setPreferredMicrophoneFieldDimension (float zoom)
```

Specifies the zoom factor (i.e. the field dimension) for the selected microphone
(for processing). The selected microphone is determined by the use-case for the stream.

<br />

| Parameters ||
|---|---|
| `zoom` | `float`: the desired field dimension of microphone capture. Range is from -1 (wide angle), though 0 (no zoom) to 1 (maximum zoom). Value is between -1.0f and 1.0f inclusive <br /> |

| Returns ||
|---|---|
| `boolean` | true if sucessful. <br /> |

### setRecordPositionUpdateListener

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

```
public void setRecordPositionUpdateListener (AudioRecord.OnRecordPositionUpdateListener listener)
```

Sets the listener the AudioRecord notifies when a previously set marker is reached or
for each periodic record head position update.

<br />

### setRecordPositionUpdateListener

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

```
public void setRecordPositionUpdateListener (AudioRecord.OnRecordPositionUpdateListener listener, 
                Handler handler)
```

Sets the listener the AudioRecord notifies when a previously set marker is reached or
for each periodic record head position update.
Use this method to receive AudioRecord events in the Handler associated with another
thread than the one in which you created the AudioRecord instance.

<br />

| Parameters ||
|---|---|
| `handler` | `Handler`: the Handler that will receive the event notification messages. <br /> |

### startRecording

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

```
public void startRecording (MediaSyncEvent syncEvent)
```

Starts recording from the AudioRecord instance when the specified synchronization event
occurs on the specified audio session.

<br />

| Parameters ||
|---|---|
| `syncEvent` | `MediaSyncEvent`: event that triggers the capture. <br /> |

| Throws ||
|---|---|
|   | java.lang.IllegalStateException |
| `https://developer.android.com/reference/java/lang/IllegalStateException` |   |

**See also:**

- `https://developer.android.com/reference/android/media/MediaSyncEvent`

### startRecording

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

```
public void startRecording ()
```

Starts recording from the AudioRecord instance.

<br />

| Throws ||
|---|---|
|   | java.lang.IllegalStateException |
| `https://developer.android.com/reference/java/lang/IllegalStateException` |   |

### stop

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

```
public void stop ()
```

Stops recording.

<br />

| Throws ||
|---|---|
|   | java.lang.IllegalStateException |
| `https://developer.android.com/reference/java/lang/IllegalStateException` |   |

### unregisterAudioRecordingCallback

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

```
public void unregisterAudioRecordingCallback (AudioManager.AudioRecordingCallback cb)
```

Unregister an audio recording callback previously registered with
`https://developer.android.com/reference/android/media/AudioRecord#registerAudioRecordingCallback(java.util.concurrent.Executor,%20android.media.AudioManager.AudioRecordingCallback)`.

<br />

| Parameters ||
|---|---|
| `cb` | `AudioManager.AudioRecordingCallback`: non-null callback to unregister <br /> |

## Protected methods

### finalize

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

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
A subclass overrides the `finalize` method to dispose of
system resources or to perform other cleanup.


The general contract of `finalize` is that it is invoked
if and when the Java virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The `finalize` method may take any action, including
making this object available again to other threads; the usual purpose
of `finalize`, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.


The `finalize` method of class `Object` performs no
special action; it simply returns normally. Subclasses of
`Object` may override this definition.


The Java programming language does not guarantee which thread will
invoke the `finalize` method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.


After the `finalize` method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.


The `finalize` method is never invoked more than once by a Java
virtual machine for any given object.


Any exception thrown by the `finalize` method causes
the finalization of this object to be halted, but is otherwise
ignored.

<br />