Added in API level 37

Builder


class Builder
kotlin.Any
   ↳ android.os.storage.operations.FileOperationRequest.Builder

Builder for constructing FileOperationRequest instances.

A builder must be initialized with an android.os.storage.operations.FileOperationRequest.OperationMode (Move or Copy). Before calling build(), a source must be specified.

Example Usage:

<code>// 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();
  </code>

Summary

Public constructors
Builder(mode: Int)

Creates a new builder for a specific file operation mode.

Public methods
FileOperationRequest

Builds the FileOperationRequest instance.

FileOperationRequest.Builder

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

FileOperationRequest.Builder

Sets the source of the file operation.

FileOperationRequest.Builder

Sets the target of the file operation.

Public constructors

Builder

Added in API level 37
Builder(mode: Int)

Creates a new builder for a specific file operation mode.

Parameters
mode Int: The operation to perform; must be OPERATION_MOVE or OPERATION_COPY.
Value is one of the following:

Public methods

build

Added in API level 37
fun build(): FileOperationRequest

Builds the FileOperationRequest instance.

Return
FileOperationRequest A new FileOperationRequest instance.
This value cannot be null.
Exceptions
java.lang.IllegalStateException if the source or target (for Move/Copy) is not set.

setRegisterCompletionListener

Added in API level 37
fun setRegisterCompletionListener(shouldRegister: Boolean): FileOperationRequest.Builder

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 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 FileOperationEnqueueResult.isSuccessful

Parameters
shouldRegister Boolean: Whether to register a completion listener.
Return
FileOperationRequest.Builder This builder instance.
This value cannot be null.

setSource

Added in API level 37
fun setSource(source: OperationSource): FileOperationRequest.Builder

Sets the source of the file operation.

Parameters
source OperationSource: The OperationSource representing the files to be operated on.
This value cannot be null.
Return
FileOperationRequest.Builder This builder instance.
This value cannot be null.

setTarget

Added in API level 37
fun setTarget(target: OperationTarget): FileOperationRequest.Builder

Sets the target of the file operation.

Parameters
target OperationTarget: The OperationTarget representing the destination of the operation.
This value cannot be null.
Return
FileOperationRequest.Builder This builder instance.
This value cannot be null.