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

# FileOperationRequest.Builder

*** ** * ** ***

` public static final class FileOperationRequest.Builder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

Builder for constructing `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest` instances.

A builder must be initialized with an `https://developer.android.com/` (Move or Copy). Before calling `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder#build()`, a source must be specified.

**Example Usage:**

    // Initialize the builder with the desired operation mode
    FileOperationRequest.Builder builder = new FileOperationRequest.Builder(
            FileOperationRequest.OPERATION_MOVE);

    // Define the source files (e.g., from the app's internal data)
    OperationSource source = new AppDataFileSource(new File(getDataDir(), "logs.db"));

    // Define the destination (e.g., a subdirectory in PCC)
    OperationTarget target = new PccTarget("archive/databases");

    // Configure and build the request
    FileOperationRequest request = builder
            .setSource(source)
            .setTarget(target)
            .build();

<br />

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder#Builder(int)(int mode) ` Creates a new builder for a specific file operation mode. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest` | ` https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder#build()() ` Builds the `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest` instance. |
| ` https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder` | ` https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder#setRegisterCompletionListener(boolean)(boolean shouldRegister) ` Sets whether a completion listener should be automatically registered for this request when it is enqueued. |
| ` https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder` | ` https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder#setSource(android.os.storage.operations.sources.OperationSource)(https://developer.android.com/reference/android/os/storage/operations/sources/OperationSource source) ` Sets the source of the file operation. |
| ` https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder` | ` https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder#setTarget(android.os.storage.operations.targets.OperationTarget)(https://developer.android.com/reference/android/os/storage/operations/targets/OperationTarget target) ` Sets the target of the 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*.

## Public constructors

### Builder

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

```
public Builder (int mode)
```

Creates a new builder for a specific file operation mode.

<br />

| Parameters ||
|---|---|
| `mode` | `int`: The operation to perform; must be `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest#OPERATION_MOVE` or `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest#OPERATION_COPY`. Value is one of the following: - `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest#OPERATION_MOVE` - `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest#OPERATION_COPY` |

## Public methods

### build

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

```
public FileOperationRequest build ()
```

Builds the `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest` instance.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest` | A new `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest` instance. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the source or target (for Move/Copy) is not set. |

### setRegisterCompletionListener

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

```
public FileOperationRequest.Builder setRegisterCompletionListener (boolean shouldRegister)
```

Sets whether a completion listener should be automatically registered for this request when it is enqueued.

If set to `true`, the calling application will receive a `https://developer.android.com/reference/android/os/storage/FileManager#ACTION_FILE_OPERATION_COMPLETED` broadcast when the operation finishes.

IMPORTANT: If the operation is rejected or fails to be queued, the listener will not be registered. Apps should ensure their requests are enqueued successfully via `https://developer.android.com/reference/android/os/storage/operations/FileOperationEnqueueResult#isSuccessful()`

<br />

| Parameters ||
|---|---|
| `shouldRegister` | `boolean`: Whether to register a completion listener. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder` | This builder instance. This value cannot be `null`. <br /> |

### setSource

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

```
public FileOperationRequest.Builder setSource (OperationSource source)
```

Sets the source of the file operation.

<br />

| Parameters ||
|---|---|
| `source` | `OperationSource`: The `https://developer.android.com/reference/android/os/storage/operations/sources/OperationSource` representing the files to be operated on. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder` | This builder instance. This value cannot be `null`. <br /> |

### setTarget

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

```
public FileOperationRequest.Builder setTarget (OperationTarget target)
```

Sets the target of the file operation.

<br />

| Parameters ||
|---|---|
| `target` | `OperationTarget`: The `https://developer.android.com/reference/android/os/storage/operations/targets/OperationTarget` representing the destination of the operation. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/storage/operations/FileOperationRequest.Builder` | This builder instance. This value cannot be `null`. <br /> |