Search code examples
androidkeyboardemojionresumechromebook

Chromebook. How do I know if my onResume is being called from the "emoji popup"?


I have a chat app for chromebook. I am in the chat and I press Search + Shift + Enter -> which brings up the "emoji popup" This calls my apps "onPause" as the dialog is on top of the app. After I select an emoji, my apps "onResume" is being called.

I was checking this:

 try {
            var newText = inputManager?.inputText
            if (newText != null && inputOnPause != null && newText.length > inputOnPause?.length ?: 0) {
                val new = newText.replace(inputOnPause!!, "")
                hasEmojis(new)
            } else false
        } catch (e: Exception) {
            false
        }

But for some reason now the "emoji" is loaded too slow so I cannot check if my onResume is being from an emoji or not. Is there a better way to know if my onResume is called due to emoji popup dialog? I checked my activity onIntent and Data/Action are null So no idea from where my textview takes the text from neither


Solution

  • If you're unable to determine if your onResume method is called specifically due to the emoji popup dialog, you can try an alternative approach to detect the emoji input. Instead of relying on the comparison of newText and inputOnPause to check for emoji input, you can utilize the inputManager to directly check if the input contains emoji characters.

    try {
        val newText = inputManager?.inputText
        if (newText != null && hasEmojis(newText)) {
            // Emoji input detected
            // Handle accordingly
        } else {
            // No emoji input
        }
    } catch (e: Exception) {
        // Error handling
    }
    

    In this code, the hasEmojis function is responsible for determining whether the input text contains any emoji characters. You can implement this function using various approaches, such as regular expressions or checking for specific Unicode ranges associated with emojis.