Browse SDKs · Android
Platform
SDKsAndroid

Create an image message

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

Copy

Construct an image message object from a file path relative to the SDK initialization data directory. When sending via Send a message, the SDK automatically compresses the image and uploads the file.

Code example

String imagePath = "images/pic_001.jpg"; // Path relative to SDK data directory

Message message = OpenIMClient.getInstance().messageManager.createImageMessage(imagePath);

Parameters

ParameterTypeRequiredDescription
imagePathStringYesFile path of the image relative to the SDK initialization data directory.

Return value

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

State changes after the call

  1. Local initialization: Initializes the local Message structure without initiating network uploads.
  2. Transmission: Call Send a message to upload and send the image. For absolute local file paths, see Create an image message from a local path.