I'm creating a custom keyboard using LinearLayout. On every key TextView click, inputConnection commits the text. It is working fine when inputConnection.commitText and inputConnection.getTextBeforeCursor is called from Activity. However, when it is called from InputMethodService then both of these functions don't work i.e., even getTextBeforeCursor returns null and commitText doesn't enter anything. Following is my InputMethodService
class MyInputMethodService : InputMethodService() {
// hold the instance of Keyboard which is shared across Host App & Extension
private lateinit var keyboardView: KeyboardView
private lateinit var myContext:Context
override fun onCreateInputView(): View {
Log.e("TKF", "onCreateInputView")
myContext = ContextThemeWrapper(this, R.style.Theme_BasicM3App)
keyboardView =
LayoutInflater.from(myContext).inflate(R.layout.fragment_keyboard, null) as KeyboardView
keyboardView.setInputConnection(currentInputConnection, true)
return keyboardView
}
}
What can be possible reasons?