Browse SDKs · Android
Platform
SDKsAndroid

Create a file message

Create a file message from a path relative to the SDK data directory.

Copy

Construct a file message object using a relative path within the SDK initialization data directory. When sending via Send a message, the SDK automatically uploads the file and tracks transfer progress.

Code example

String filePath = "documents/annual_report.pdf";
String fileName = "Annual_Report.pdf";

Message message = OpenIMClient.getInstance().messageManager.createFileMessage(
    filePath,
    fileName
);

Parameters

ParameterTypeRequiredDescription
filePathStringYesFile path relative to the SDK initialization data directory.
fileNameStringYesDisplay name of the file (such as Annual_Report.pdf), used by the receiver for display and saving.

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 upload and send the file. For absolute local filesystem paths, see Create a file message from a local path.