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

# MessageQueue.OnFileDescriptorEventListener

*** ** * ** ***


`
public
static


interface
MessageQueue.OnFileDescriptorEventListener
`


`


`

|---|
| android.os.MessageQueue.OnFileDescriptorEventListener |

<br />

*** ** * ** ***

A listener which is invoked when file descriptor related events occur.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_ERROR` File descriptor event: Indicates that the file descriptor encountered a fatal error. |
| `int` | `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_INPUT` File descriptor event: Indicates that the file descriptor is ready for input operations, such as reading. |
| `int` | `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_OUTPUT` File descriptor event: Indicates that the file descriptor is ready for output operations, such as writing. |

| ### Public methods ||
|---|---|
| ` abstract int` | ` https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#onFileDescriptorEvents(java.io.FileDescriptor,%20int)(https://developer.android.com/reference/java/io/FileDescriptor fd, int events) ` Called when a file descriptor receives events. |

## Constants

### EVENT_ERROR

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

```
public static final int EVENT_ERROR
```

File descriptor event: Indicates that the file descriptor encountered a
fatal error.


File descriptor errors can occur for various reasons. One common error
is when the remote peer of a socket or pipe closes its end of the connection.


This event may be generated at any time regardless of whether the
`https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_ERROR` event mask was specified when the listener was added.

<br />

<br />

Constant Value:

4
(0x00000004)


### EVENT_INPUT

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

```
public static final int EVENT_INPUT
```

File descriptor event: Indicates that the file descriptor is ready for input
operations, such as reading.


The listener should read all available data from the file descriptor
then return `true` to keep the listener active or `false`
to remove the listener.


In the case of a socket, this event may be generated to indicate
that there is at least one incoming connection that the listener
should accept.


This event will only be generated if the `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_INPUT` event mask was
specified when the listener was added.

<br />

<br />

Constant Value:

1
(0x00000001)


### EVENT_OUTPUT

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

```
public static final int EVENT_OUTPUT
```

File descriptor event: Indicates that the file descriptor is ready for output
operations, such as writing.


The listener should write as much data as it needs. If it could not
write everything at once, then it should return `true` to
keep the listener active. Otherwise, it should return `false`
to remove the listener then re-register it later when it needs to write
something else.


This event will only be generated if the `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_OUTPUT` event mask was
specified when the listener was added.

<br />

<br />

Constant Value:

2
(0x00000002)


## Public methods

### onFileDescriptorEvents

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

```
public abstract int onFileDescriptorEvents (FileDescriptor fd, 
                int events)
```

Called when a file descriptor receives events.

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: The file descriptor. This value cannot be `null`. <br /> |
| `events` | `int`: The set of events that occurred: a combination of the `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_INPUT`, `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_OUTPUT`, and `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_ERROR` event masks. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_INPUT` - `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_OUTPUT` - `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_ERROR` |

| Returns ||
|---|---|
| `int` | The new set of events to watch, or 0 to unregister the listener. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_INPUT` - `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_OUTPUT` - `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_ERROR` |

**See also:**

- `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_INPUT`
- `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_OUTPUT`
- `https://developer.android.com/reference/android/os/MessageQueue.OnFileDescriptorEventListener#EVENT_ERROR`