Implementation of comet chat sdk in kotlin

197 Views Asked by At

I have been trying to implement come chat into my app and it has been really difficult for some days now. I finally initialized it but it gives me an error when i try to implement it when a user logs in. Here is my code below

private fun logChat() {
    val UID: String? = FirebaseAuth.getInstance().currentUser?.uid // Replace with the UID of the user to login
    val AUTH_KEY = "a7cd1825ba915ecc3732c8896ae7f2f4fa9d4b5d" // Replace with your App Auth Key
    CometChat.login(UID.toString(), AUTH_KEY, object : CometChat.CallbackListener<User?>() {
        override fun onSuccess(user: User?) {

        }

        override fun onError(e: CometChatException) {

        }
    })
}

It gives the following error: Type mismatch. Required: CometChat.CallbackListener<User!> Found:

But it doesnt indicate what was found. Please help me

2

There are 2 best solutions below

0
On

Add import com.cometchat.pro.models.User. Nice to help you

0
On

change your code to like this

    private fun logChat() {
    val UID: String? = FirebaseAuth.getInstance().currentUser?.uid // Replace with the UID of the user to login
    val AUTH_KEY = "a7cd1825ba915ecc3732c8896ae7f2f4fa9d4b5d" // Replace with your App Auth Key
    CometChat.login(UID.toString(), AUTH_KEY, object : CometChat.CallbackListener<User>() {
        override fun onSuccess(user: User) {

        }

        override fun onError(e: CometChatException) {

        }
    })
}

sdk source code define method parameter NonNull

public static void login(@androidx.annotation.NonNull java.lang.String s, @androidx.annotation.NonNull java.lang.String s1, @androidx.annotation.NonNull com.cometchat.pro.core.CometChat.CallbackListener<com.cometchat.pro.models.User> callbackListener) { /* compiled code */ }