How do I get the token required for hideSoftInputFromInputMethod(token, flags)?
So I’m trying to make an android IME. I need an ability to hide the IME from my IME itself.
So far I’ve only seen examples of how to show\hide IMEs from Activity, but I need to do this from within the IME.
I found InputMethodManager.hideSoftInputFromInputMethod(token, flags),
but it needs token, but I don’t know how to get it. getCurrentInputBinding().getConnectionToken()
does not work – it crashes the application. Any ideas?
Solution
Presumably, based on answers to this question elsewhere (I’m still trying to figure out a consistent way of working myself), the token you need is from yourTextView.getWindowToken().
However, this doesn’t work for me, and I’ve seen a lot of people have the same tip.
[edit].
Using the markup specified above, I had better luck hiding the keyboard with hideSoftInputFromWindow instead of hideSoftInputFromInputMethod. Although since I didn’t grasp the difference between these features at first, I may not understand your actual question. Sorry!
[/edit]