Skip to content

Instantly share code, notes, and snippets.

View AlexPrestonSB's full-sized avatar

Alex Preston AlexPrestonSB

View GitHub Profile
@AlexPrestonSB
AlexPrestonSB / build.gradle
Created August 27, 2020 17:04
Add the Sendbird SDK to the app level gradle file where your other dependencies reside.
dependencies {
implementation 'com.sendbird.sdk:sendbird-android-sdk:3.0.141'
...
}
@AlexPrestonSB
AlexPrestonSB / SenderReadReceipt.java
Last active August 7, 2020 21:44
Getting updates for read receipts.
//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 August 7, 2020 21:43
Marking a message as read.
//Receiver Side
// Call the 'markAsRead()' when the current user views unread messages in a group channel.
groupChannel.markAsRead();
...
@AlexPrestonSB
AlexPrestonSB / ReceiverMarkAsRead.java
Created August 7, 2020 21:36
Marking a message as read
//Receiver Side
// Call the 'markAsRead()' when the current user views unread messages in a group channel.
groupChannel.markAsRead();
...
@AlexPrestonSB
AlexPrestonSB / SenderDeliveryReceipt.java
Last active August 7, 2020 21:43
Sender side for getting an update for messages that are marked as delivered.
//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 August 7, 2020 21:42
Receiver side for marking messages as delivered.
//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 August 7, 2020 21:41
Snippet showing how to set the retry policy for Sync Manager.
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 August 7, 2020 21:41
Getting messages from the server.
@Override
protected void onResume() {
super.onResume();
SendBird.addConnectionHandler(YOUR_CONNECTION_HANDLER_ID, new SendBird.ConnectionHandler() {
@Override
public void onReconnectStarted() {
SendBirdSyncManager.getInstance().pauseSync();
}
@AlexPrestonSB
AlexPrestonSB / FailedMessage.java
Created August 7, 2020 21:27
Event for when a message fails to send.
@Override
public void onFailedMessageEvent(MessageCollection collection, final List<BaseMessage> messages, final MessageEventAction action, final FailedMessageEventActionReason reason) {
if (getActivity() == null) {
return;
}
}
@AlexPrestonSB
AlexPrestonSB / TypingIndicator.java
Last active August 7, 2020 21:40
Receiving Typing Indicators.
//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())) {