Search code examples
androidkotlinchat

Getting Error while creating conversation type channel in Amity Cloud sdk


AmityChatClient.newChannelRepository() .createChannel(displayName = name) .conversation(id) .build() .create() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSuccess { onChatCreateSuccess.invoke(it.getChannelId()) } .doOnError { onChatCreateFailed.invoke(it.toString()) } .ignoreElement()

I have logged In but every time I run the code getting error

com.amity.socialcloud.sdk.model.core.error.AmityException: Please login to use SDK


Solution

  • this is Eliza from Amity. It looks like you haven't called the initialization on the app level.

    class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        AmityCoreClient.setup(
            apiKey = "YOUR_API_KEY",
            endpoint = AmityEndpoint.EU // or whichever server you selected on the portal
        )
    }
    

    }

    If that's not the case, are you listening to any changes happening in the session as shown below?

    AmityCoreClient.observeSessionState().asFlow()
    

    Any calls to the repositories should only happen within an active session.