Suggestions

close search

Messages

Once authenticated, users can send or receive messages such as text, photos, videos, audio, locations, contacts... In order to send a message containing media content (photos, videos, audio, etc.), first, you need to upload media content to your server. 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 the 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

Get local messages of a conversation by calling:

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

In which:

3.2. Get latest messages

Get the latest messages from the Stringee server by calling:

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

In which:

3.3. Get messages after

Get a list of messages tied to a conversation from the server which has a sequence greater than seq by calling:

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

In which:

3.4. Get messages before

Get a list of messages tied to a conversation from the server which has a sequence smaller than seq by calling:

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 delivery status of each message to the recipient. There are five possible statuses: INITIALIZED, SENDING, SENT, DELIVERED, READ. Stringee automatically updates the recipient status to SENT and DELIVERED. The only update your app can perform is marking a conversation's messages as read:

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

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

5. Delete messages

Delete messages by calling:

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

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

In which:

6. Pin/Unpin a message

Pin or unpin a message by calling:

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

    }

    @Override
    public void onError(StringeeError error) {

    }
});

In which: