Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/os/storage/FileManager#constants) \| [Methods](https://developer.android.com/reference/android/os/storage/FileManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/os/storage/FileManager#inhmethods)

# FileManager

*** ** * ** ***


`
public

final

class
FileManager
`


`

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


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.os.storage.FileManager |

<br />

*** ** * ** ***

System service manager for handling privileged, long-running file operations.

The `FileManager` provides an API for applications to request asynchronous file
operations such as moving or copying files. These operations are executed by the system service
(\`FileService\`) on a background thread to ensure application responsiveness and system stability.

### Usage Overview

Interacting with the file operation service generally involves three steps:

1. **Enqueueing a Request:** Use `https://developer.android.com/reference/android/os/storage/FileManager#enqueueOperation(android.os.storage.operations.FileOperationRequest)` to submit a new operation. This method returns immediately with a `https://developer.android.com/reference/android/os/storage/operations/FileOperationEnqueueResult`, which contains a unique Request ID (if successful) or an error code (if the system is busy).
2. **Tracking Progress (Optional):** Apps can poll the current status of an operation using `https://developer.android.com/reference/android/os/storage/FileManager#fetchResult(java.lang.String)` or simply wait for completion.
3. **Handling Completion:** To receive a notification when the operation finishes (either successfully or with a failure), call `https://developer.android.com/reference/android/os/storage/FileManager#registerCompletionListener(java.lang.String)`. The system will send a broadcast `https://developer.android.com/reference/android/os/storage/FileManager#ACTION_FILE_OPERATION_COMPLETED` to your package when the operation reaches a terminal state.

### Concurrency and Limits

The system enforces limits on the number of concurrent pending operations to prevent resource
exhaustion. If the system is under heavy load, `https://developer.android.com/reference/android/os/storage/FileManager#enqueueOperation(android.os.storage.operations.FileOperationRequest)`
may return a result with the error code `https://developer.android.com/reference/android/os/storage/operations/FileOperationResult#ERROR_BUSY`. Applications should handle this
case gracefully, potentially by retrying later.

Additionally, the system caps the number of individual file failures reported in a `https://developer.android.com/reference/android/os/storage/operations/FileOperationResult` to the value returned from `https://developer.android.com/`. If granular failure reporting is critical for your use case, avoid
enqueueing operations that involve more files than the failure reporting limit in a single
request.

## Summary

| ### Constants ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/os/storage/FileManager#ACTION_FILE_OPERATION_COMPLETED` Broadcast Action: Sent when a file operation has completed. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/os/storage/FileManager#EXTRA_REQUEST_ID` Extra for `https://developer.android.com/reference/android/os/storage/FileManager#ACTION_FILE_OPERATION_COMPLETED`: The Request ID (String). |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/os/storage/FileManager#EXTRA_RESULT` Extra for `https://developer.android.com/reference/android/os/storage/FileManager#ACTION_FILE_OPERATION_COMPLETED`: The result (`https://developer.android.com/reference/android/os/storage/operations/FileOperationResult`). |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/os/storage/operations/FileOperationEnqueueResult` | ` https://developer.android.com/reference/android/os/storage/FileManager#enqueueOperation(android.os.storage.operations.FileOperationRequest)(https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest request) ` Enqueues a new file operation request. |
| ` https://developer.android.com/reference/android/os/storage/operations/FileOperationResult` | ` https://developer.android.com/reference/android/os/storage/FileManager#fetchResult(java.lang.String)(https://developer.android.com/reference/java/lang/String requestId) ` Retrieves the current result of a file operation. |
| ` static int` | ` https://developer.android.com/reference/android/os/storage/FileManager#getMaxReportedFailures()() ` Due to binder transaction limits, the number of reported failures is limited to number returned by this method. |
| ` void` | ` https://developer.android.com/reference/android/os/storage/FileManager#registerCompletionListener(java.lang.String)(https://developer.android.com/reference/java/lang/String requestId) ` Registers a listener for the completion of a specific file operation. |
| ` void` | ` https://developer.android.com/reference/android/os/storage/FileManager#unregisterCompletionListener(java.lang.String)(https://developer.android.com/reference/java/lang/String requestId) ` Unregisters a previously registered completion listener for a specific file operation. |

| ### 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*. | ||

## Constants

### ACTION_FILE_OPERATION_COMPLETED

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

```
public static final String ACTION_FILE_OPERATION_COMPLETED
```

Broadcast Action: Sent when a file operation has completed.

This broadcast is sent explicitly to the package that initiated the request and registered
for notifications via `https://developer.android.com/reference/android/os/storage/FileManager#registerCompletionListener(java.lang.String)`.

The intent will contain the following extras:

- `https://developer.android.com/reference/android/os/storage/FileManager#EXTRA_REQUEST_ID` - The unique ID of the request that completed.
- `https://developer.android.com/reference/android/os/storage/FileManager#EXTRA_RESULT` - The final `https://developer.android.com/reference/android/os/storage/operations/FileOperationResult` of the operation, including status (FINISHED/FAILED), items processed, and any error messages.

<br />

<br />

Constant Value:

"android.os.storage.action.FILE_OPERATION_COMPLETED"


### EXTRA_REQUEST_ID

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

```
public static final String EXTRA_REQUEST_ID
```

Extra for `https://developer.android.com/reference/android/os/storage/FileManager#ACTION_FILE_OPERATION_COMPLETED`: The Request ID (String).

This ID matches the one returned by `https://developer.android.com/reference/android/os/storage/FileManager#enqueueOperation(android.os.storage.operations.FileOperationRequest)`.

<br />

Constant Value:

"android.os.storage.extra.REQUEST_ID"


### EXTRA_RESULT

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

```
public static final String EXTRA_RESULT
```

Extra for `https://developer.android.com/reference/android/os/storage/FileManager#ACTION_FILE_OPERATION_COMPLETED`: The result (`https://developer.android.com/reference/android/os/storage/operations/FileOperationResult`).

This parcelable object contains detailed information about the final state of the
operation.

<br />

Constant Value:

"android.os.storage.extra.RESULT"


## Public methods

### enqueueOperation

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

```
public FileOperationEnqueueResult enqueueOperation (FileOperationRequest request)
```

Enqueues a new file operation request.

This method validates the request and submits it to the system service. It returns
immediately, without waiting for the operation to execute.

If the system is too busy to accept the request, the returned result will have an error
code of `https://developer.android.com/reference/android/os/storage/operations/FileOperationResult#ERROR_BUSY`.

**Note:** Granular failure reporting is limited to the first 200 failures encountered.
For operations where reporting every individual failure is required, it is recommended to
break large tasks into multiple requests of 200 files or fewer.

<br />

| Parameters ||
|---|---|
| `request` | `FileOperationRequest`: The `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest` describing the operation (source, target, mode). This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/storage/operations/FileOperationEnqueueResult` | A `https://developer.android.com/reference/android/os/storage/operations/FileOperationEnqueueResult` containing the Request ID (on success) or an error code (on failure). This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if the system service is unreachable. |

### fetchResult

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

```
public FileOperationResult fetchResult (String requestId)
```

Retrieves the current result of a file operation.

The system maintains result information for all active operations and a limited history of
recently completed ones.

<br />

| Parameters ||
|---|---|
| `requestId` | `String`: The unique ID of the request to query, as returned by `https://developer.android.com/reference/android/os/storage/FileManager#enqueueOperation(android.os.storage.operations.FileOperationRequest)`. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/storage/operations/FileOperationResult` | A `https://developer.android.com/reference/android/os/storage/operations/FileOperationResult` object containing the current status, or `null` if the request ID is unknown or has been culled from history. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if the system service is unreachable. |

### getMaxReportedFailures

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

```
public static int getMaxReportedFailures ()
```

Due to binder transaction limits, the number of reported failures is limited to number
returned by this method. It is recommended that operations that require complete failure
reporting batch their operations to stay below the max reported failures limit.

<br />

| Returns ||
|---|---|
| `int` | The maximum number of reported failures reported by File operations. <br /> |

### registerCompletionListener

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

```
public void registerCompletionListener (String requestId)
```

Registers a listener for the completion of a specific file operation.

When the operation identified by `requestId` finishes (successfully or with an
error), the system will send a `https://developer.android.com/reference/android/os/storage/FileManager#ACTION_FILE_OPERATION_COMPLETED` broadcast to the
calling application.

This method should be called immediately after a successful `https://developer.android.com/reference/android/os/storage/FileManager#enqueueOperation(android.os.storage.operations.FileOperationRequest)` if
completion notification is desired.

<br />

| Parameters ||
|---|---|
| `requestId` | `String`: The unique ID of the request to monitor, as returned by `https://developer.android.com/reference/android/os/storage/FileManager#enqueueOperation(android.os.storage.operations.FileOperationRequest)`. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if the system service is unreachable. |

### unregisterCompletionListener

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

```
public void unregisterCompletionListener (String requestId)
```

Unregisters a previously registered completion listener for a specific file operation.

<br />

| Parameters ||
|---|---|
| `requestId` | `String`: The unique ID of the request to stop monitoring. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if the system service is unreachable. |