[Android] SendBird SDK 정리

성승모·2026년 2월 26일

Android

목록 보기
10/10

시작하기

세팅

  1. 대시보드 세팅
  2. 설정

Note!
아래 모든 함수들은 모두 비동기 작업. 따라서, callback Handler를 달아서 하는게 좋다. 특히, channel 권장

코드 시작

init

  • fun init(initParams: InitParams, handler: InitResultHandler): Unit
    • InitParams.useLocalCaching: 로컬 스토리지 사용 여부
    • InitResultHandler
      • onMigrationStarted(): 로컬 db에 갱신 사항이 있을 경우
      • onInitFailed() -> useLocalCaching이 true여도 false로 해버림.
      • onInitSucceeded()
    -> 만약, 다시 하고 싶으면, SendBird.clearCachedData 후 다시 init 호출
SendbirdChat.init(
    InitParams(APP_ID, applicationContext, useCaching = true),
    object : InitResultHandler {
        override fun onMigrationStarted() {
            Log.i("Application", "Called when there's an migration in local cache.")
        }

        override fun onInitFailed(e: SendbirdException) {
            when (e.code) {
                SendbirdError.ERR_INITIALIZATION_CANCELED -> {
                    Log.i("Application", "Called when initialize failed for some reason such as empth APP_ID. Retry SendbirdChat.init() again with correct InitParams.")
                }
                SendbirdError.ERR_DATABASE_ERROR_ENCRYPTION -> {
                    Log.i("Application", "Called when initialize failed when InitParams.LocalCacheConfig.SqlcipherConfig is set but SqlCipher dependency is not set. Please add the dependency and try SendbirdChat.init again.")
                }
                else -> {
                    Log.i("Application", "Called when initialize failed. SDK will still operate properly as if useLocalCaching is set to false.")
                }
            }
        }

        override fun onInitSucceed() {
            Log.i("Application", "Called when initialization is completed.")
        }
    }
)

connect

  • channel에 먼저 connect 해야 함.
  • 당연히 unique한 키가 있어야 함.
  • fun connect(userId: String, authToken: String? = COMPILED_CODE, handler: ConnectHandler?): Unit
    • handler는 User를 리턴함.
SendbirdChat.connect(userId) { user, e ->
    if (user != null) {
        if (e != null) {
            // Proceed in offline mode with the data stored in the local database.ConnectionHandler.onReconnectSucceeded().
        } else {
            // Proceed in online mode.
        }
    } else {
        // Handle error.
    }
}

무조건 init이 성공한 이후 불러야함.

Open

  • 같은 어플리케이션 내 모든 SendBird 유저가 들어올 수 있는 방
  • openChannel 사용
OpenChannel.createChannel(OpenChannelCreateParams()) { channel, e ->
    if (e != null) {
        // Handle error.
    }

    // An open channel is successfully created.
}

Enter

  • static 메소드 이용
OpenChannel.createChannel(OpenChannelCreateParams()) { channel, e ->
    if (e != null) {
        // Handle error.
    }

    // Call the instance method of the result object in the openChannel parameter
    channel?.enter { e ->
        if (e != null) {
            // Handle error.
        }

        // The current user has successfully entered the open channel,
    }
}

Send

  • Enter 후 가져온 OpenChannel 객체에서 sendUserMessage 호출
openChannel.sendUserMessage(UserMessageCreateParams(MESSAGE)) { message, e ->
    if (e != null) {
        // Handle error.
    }

    // The message has been successfully sent to the channel.
}

빠른 문서

User

  1. 타입
  • User: SendBird Application 내 전체
  • Participant: 해당 channel 내부 사용자
  • Member: Group Channel에 속해 있는 사용자
  1. 핵심 함수

Channel

  1. 타입
  • OpenChannel: 공공 채팅방으로, 간편하게 나갔다 들어갔다 할 수 있다. 초대 없이!
    • classic: 1,000명까지 가능. (곧, 사라질 예정)
    • dynamic: 더 많은 숫자 가능. 내부적으로 subChannel 사용
  • GroupChannel: 몇몇에게 제한된 채팅방으로, 초대가 필요함! super를 넘겨주면 매우 큰
    • private: 오직 초대만을 통해 입장 가능 -> 1대1 같은?
    • public: 아무나 들어올 수 있음. -> 1대다

distinct = false : 유저 A,B,C가 기존 Channel이 아닌 새로운 Channel을 만들어도, 기존 Channel이 사용됨
super = true: 매우 많은 사용자를 참여시킬 수 있음.

  • super가 true면 distinct 지원 X
  1. Supergroup channel 제한
  • 읽음 확인 제공 X
  • 읽지 않은 카운트 max == 99
  • Push Notification
    • 100 이하: 가능
    • 100 이상: 첫 푸시 후 10분 동안 X
    • Channel에 들어와 Active된 유저: 1분 동안 모든 푸시 O
  1. 핵심 함수

메시지

  1. 타입
  • Text: String 값.
  • File:
  • Multiple File: Group Channel에서만 가능 30개 까지, 하나 당 25MB
  • Admin: 시스템 메시지. Chat API나 대시보드에서 전송
  1. 핵심 함수
profile
안녕하세요!

0개의 댓글