Browse SDKs · Android
Platform
SDKsAndroid

Create a file message from a local path

Create a file message from an absolute path.

Copy

Construct a file message object using an absolute filesystem path on the local device (such as a document picked from the system file picker). When sending via Send a message, the SDK reads the local file and automatically performs the upload.

Code example

String absolutePath = "/storage/emulated/0/Download/specs.docx";
String fileName = "Requirements_Specification.docx";

Message message = OpenIMClient.getInstance().messageManager.createFileMessageFromFullPath(
    absolutePath,
    fileName
);

Parameters

ParameterTypeRequiredDescription
filePathStringYesAbsolute filesystem path of the file on the local device. Ensure read permissions are granted.
fileNameStringYesDisplay name of the file presented to recipients (including file extension).

Return value

Returns the created Message object with contentType set to MessageType.FILE.

State changes after the call

  1. Local initialization: Initializes the local Message structure without starting network uploads.
  2. Transmission: Call Send a message to deliver the file message to a single user or group.