Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use the Android InputMethodManager on a custom in-app keyboard?

The InputMethodManager is a service that apps can use to interact with the system keyboards. Editors like EditText also use it to indirectly notify the keyboards of changes (for example, updateSelection).

I can get a reference to the InputMethodManager like this

InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

My problem is that this seems to be just for system keyboards. Can I use the InputMethodManager for a custom in-app keyboard? If it was for just one isolated app I wouldn't care but I am including a custom keyboard in a library that will be used in many apps. I need a standard way for editors to communicate with the keyboard.

Do I have to write my own input method manager or is there a way to use the standard InputMethodManager with my custom in-app keyboard?

Update

Here are some clues for how I might implement my own custom input method manager if there is no way to use the standard one.

  • InputMethodManager (documentation) (source code)
  • InputMethod interface
  • InputMethodSession interface
  • KeyboardView.OnKeyboardActionListener interface (keyboards implement it)
  • InputMethodService (keyboards extend this) (documentation) (source code)
like image 494
Suragch Avatar asked Jul 20 '17 05:07

Suragch


1 Answers

You should implement yours.

InputMethodService provides a standard implementation of an InputMethod, which final implementations can derive from and customize. See the base class AbstractInputMethodService and the InputMethod interface for more information on the basics of writing input methods.

like image 130
devgianlu Avatar answered Nov 02 '22 04:11

devgianlu