Suggestions

close search

Messages

Once authenticated, users can send or received messages such as text, photo, video, audio, location, contact... To send a message contains media content (photo, video, audio, file...), you need to upload media content to your server first. Then you use Stringee SDK to send the uploaded URL.

1. Create a message

Instantiate a text message by calling:

Message message = new Message(text);

In which:

To instantiate other types of message, you call:

Message message = new Message(type);

In which:

Following message types are supported:

2. Send a message

2.1 Send a text message

Message message = new Message(text);
conversation.sendMessage(stringeeClient, message, new StatusListener() {
    @Override
    public void onSuccess() {
    }

    @Override
    public void onError(StringeeError error) {
    }
});

2.2 Send a message with an attachment

Message message = new Message(type); // Photo, Audio, Video, File Message
message.setFilePath(filepath);   // The path of the attachment on your device
message.setDuration(duration);  // For Audio, Video Message, in milisecond
conversation.sendMessage(stringeeClient, message, new StatusListener() {
    @Override
    public void onSuccess() {
    }

    @Override
    public void onError(StringeeError error) {
    }
});

2.3 Send a location

Message message = new Message(type); 
message.setLatitude(latitude);
message.setLongitude(longitude);
conversation.sendMessage(stringeeClient, message, new StatusListener() {
    @Override
    public void onSuccess() {
    }

    @Override
    public void onError(StringeeError error) {
    }
});

2.4 Send a contact

Message message = new Message(type); 
message.setContact(vCardContact); // Send a contact in vcard format
conversation.sendMessage(stringeeClient, message, new StatusListener() {
    @Override
    public void onSuccess() {
    }

    @Override
    public void onError(StringeeError error) {
    }
});

2.5 Send a sticker

Message message = new Message(type);
message.setStickerCategory(category);
message.setStickerName(name);
conversation.sendMessage(stringeeClient, message, new StatusListener() {
    @Override
    public void onSuccess() {
    }
});

Before you can send/receive a sticker, you must upload sticker sets to your server first.

3. Get Messages

Messages are stored on Stringee server and cached on the local database as well. You can get messages as follows:

3.1. Get local messages

To get local messages of a conversation, you call:

conversation.getLocalMessages(stringeeClient, count, new CallbackListener<List<Message>>() {
    @Override
    public void onSuccess(List<Message> messageList) {
    }
});

In which:

3.2. Get latest messages

To get latest messages from Stringee server, you call:

conversation.getLastMessages(stringeeClient, count, new CallbackListener<List<Message>>() {
    @Override
    public void onSuccess(final List<Message> messages1) {
    }
});

In which:

3.3. Get messages after

To get a list of messages tied to a conversation from server which have sequence greater than seq, you call:

conversation.getMessagesAfter(stringeeClient, seq, count, new CallbackListener<List<Message>>() {
    @Override
    public void onSuccess(final List<Message> lstMessages) {
    }
});

In which:

3.4. Get messages before

To get a list of messages tied to a conversation from server which have sequence smaller than seq, you call:

conversation.getMessagesBefore(stringeeClient, seq, count, new CallbackListener<List<Message>>() {
    @Override
    public void onSuccess(final List<Message> lstMessages) {
    }
});

In which:

4. Message statuses

Stringee keeps track of the recipient status of each message. There are five possible statuses: INITIALIZE, SENDING, SENT, DELIVERED, READ. Stringee automatically updates the recipient status to sent, delivered. The only update your app can perform is to mark a conversation's messages as read:

message.markAsRead(stringeeClient, new StatusListener() {
    @Override
    public void onSuccess() {
    }
});

Stringee notify you the status update of a message via the onChangeEvent event of StringeeClient.

5. Delete messages

To delete messages, you call:

conversation.deleteMessages(stringeeClient, messages, new StatusListener() {
    @Override
    public void onSuccess() {
    }

    @Override
    public void onError(StringeeError error) {
    }
});

In which:

6. Pin/Unpin a message

To pin or unpin a message, you call:

message.pinOrUnpin(stringeeClient, pinOrUnpin, new StatusListener() {
    @Override
    public void onSuccess() {

    }

    @Override
    public void onError(StringeeError error) {

    }
});

In which: