Browse SDKs · Android
Platform
SDKsAndroid

Create an audio message from a local path

Create an audio message from an absolute path.

Copy

Construct a voice or audio message object from an absolute filesystem path recorded on the local device. When sending via Send a message, the SDK automatically uploads the file and tracks progress.

Code example

String absolutePath = "/storage/emulated/0/Recordings/voice_sample.m4a";
long durationSeconds = 8L; // Duration: 8 seconds

Message message = OpenIMClient.getInstance().messageManager.createSoundMessageFromFullPath(
    absolutePath,
    durationSeconds
);

Parameters

ParameterTypeRequiredDescription
soundPathStringYesAbsolute filesystem path of the audio file on the local device. Ensure read permissions are granted.
durationlongYesAudio playback duration in seconds.

Return value

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

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 deliver the audio message.