Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Preston AlexPrestonSB

View GitHub Profile
@AlexPrestonSB
AlexPrestonSB / build.gradle
Created Aug 27, 2020
Add the Sendbird SDK to the app level gradle file where your other dependencies reside.
View build.gradle
dependencies {
implementation 'com.sendbird.sdk:sendbird-android-sdk:3.0.141'
...
}
@AlexPrestonSB
AlexPrestonSB / SenderReadReceipt.java
Last active Aug 7, 2020
Getting updates for read receipts.
View SenderReadReceipt.java
//Sender Side
// To listen to an update from all the other channel members' client apps, implement the 'onReadReceiptUpdated()' with things to do when notified.
SendBird.addChannelHandler(UNIQUE_HANDLER_ID, new SendBird.ChannelHandler() {
@Override
public void onReadReceiptUpdated(GroupChannel groupChannel) {
if (currentGroupChannel.getUrl().equals(groupChannel.getUrl())) {
// For example, code for redrawing a channel view.
}
}
});
@AlexPrestonSB
AlexPrestonSB / ReceiverMarkAsRead.java
Last active Aug 7, 2020
Marking a message as read.
View ReceiverMarkAsRead.java
//Receiver Side
// Call the 'markAsRead()' when the current user views unread messages in a group channel.
groupChannel.markAsRead();
...
@AlexPrestonSB
AlexPrestonSB / SenderDeliveryReceipt.java
Last active Aug 7, 2020
Sender side for getting an update for messages that are marked as delivered.
View SenderDeliveryReceipt.java
//Sender’s side
SendBird.addChannelHandler(UNIQUE_HANDLER_ID, new SendBird.ChannelHandler() {
@Override
public void onMessageReceived(BaseChannel baseChannel, BaseMessage baseMessage) {
}
@Override
public void onDeliveryReceiptUpdated(GroupChannel channel) {
...
@AlexPrestonSB
AlexPrestonSB / ReceiverMarkAsDelivered.java
Last active Aug 7, 2020
Receiver side for marking messages as delivered.
View ReceiverMarkAsDelivered.java
//Receiver Side
public class FirebaseMessagingServiceEx extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
JSONObject sendBird = new JSONObject(remoteMessage.getData().get("sendbird"));
JSONObject channel = (JSONObject) sendBird.get("channel");
String channelUrl = (String) channel.get("channel_url");
//Mark the Message as Delivered
@AlexPrestonSB
AlexPrestonSB / MessageResend.java
Last active Aug 7, 2020
Snippet showing how to set the retry policy for Sync Manager.
View MessageResend.java
SendBirdSyncManager.Options options = new SendBirdSyncManager.Options.Builder()
.setMessageResendPolicy(SendBirdSyncManager.MessageResendPolicy.AUTOMATIC)
.setAutomaticMessageResendRetryCount(5)
.build();
SendBirdSyncManager.setup(context, userId, options, handler);
@AlexPrestonSB
AlexPrestonSB / SyncManager.java
Last active Aug 7, 2020
Getting messages from the server.
View SyncManager.java
@Override
protected void onResume() {
super.onResume();
SendBird.addConnectionHandler(YOUR_CONNECTION_HANDLER_ID, new SendBird.ConnectionHandler() {
@Override
public void onReconnectStarted() {
SendBirdSyncManager.getInstance().pauseSync();
}
@AlexPrestonSB
AlexPrestonSB / TypingIndicator.java
Last active Aug 7, 2020
Receiving Typing Indicators.
View TypingIndicator.java
//Sender Side
groupChannel.startTyping(); //Sender Side
groupChannel.endTyping();
...
//Receiver side
// To listen to an update from all the other channel members' client apps, implement the 'onTypingStatusUpdated()' with things to do when notified.
SendBird.addChannelHandler(UNIQUE_HANDLER_ID, new SendBird.ChannelHandler() {
@Override
public void onTypingStatusUpdated(GroupChannel groupChannel) {
if (currentGroupChannel.getUrl().equals(groupChannel.getUrl())) {
@AlexPrestonSB
AlexPrestonSB / FileMessage.java
Last active Aug 7, 2020
Sending a File Message.
View FileMessage.java
//File Message
// Sending a file message with a raw file
List<FileMessage.ThumbnailSize> thumbnailSizes = new ArrayList<>();
thumbnailSizes.add(new ThumbnailSize(100,100));
FileMessageParams params = new FileMessageParams()
.setFile(FILE)
.setFileName(FILE_NAME)
.setFileSize(FILE_SIZE)
.setMimeType(MIME_TYPE)
View ReceiverMarkAsRead.java
//Receiver Side
// Call the 'markAsRead()' when the current user views unread messages in a group channel.
groupChannel.markAsRead();
...