AndroidでSendBirdを使い始めました。1in1チャットをしたいのでSendBirdに接続し、ハンドラを設定し、チャンネルを作成してメッセージを送信しましたが、onMessageReceivedが機能しません。以下のコードを参照してください。
var handler = object : SendBird.ConnectHandler{
override fun onConnected(p0: User?, p1: SendBirdException?) {
SendBird.addChannelHandler(UNIQUE_HANDLER_ID, object : SendBird.ChannelHandler() {
override fun onMessageReceived(p0: BaseChannel?, p1: BaseMessage?) {
Log.d(TAG, "addChannelHandler - onMessageReceived - messageId ${p1?.messageId}")
Log.d(TAG, "addChannelHandler - onMessageReceived - channelUrl ${p1?.channelUrl}")
if (p1 is UserMessage) {
Log.d(TAG, "addChannelHandler - onMessageReceived - messageId ${p1?.message}")
}
}
})
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
SendBird.connect("222222", handler)
SendBird.connect("111111", object : SendBird.ConnectHandler {
override fun onConnected(p0: User?, p1: SendBirdException?) {
Log.d(TAG, " SendBird.connect - userID - " + p0?.userId)
var list = mutableListOf("111111", "222222")
var params = GroupChannelParams()
params.setDistinct(true)
.addUserIds(list)
GroupChannel.createChannel(params, object : GroupChannel.GroupChannelCreateHandler {
override fun onResult(p0: GroupChannel?, p1: SendBirdException?) {
groupChannel?.sendUserMessage("Hello", object : BaseChannel.SendUserMessageHandler {
override fun onSent(p0: UserMessage?, p1: SendBirdException?) {
Log.d(TAG, "sendUserMessage - onSent - ${p0?.message}")
}
})
}
})