7

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.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • I decided to go the route of making my own custom input method manager. I don't think it is possible to use the system `InputMethodManager` because it involves security issues with the phone. However, I added the bounty just to make sure before I completely abandon the idea. – Suragch Aug 31 '17 at 14:19

2 Answers2

1

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.

devgianlu
  • 1,547
  • 13
  • 25
1

No, you can't. Because if you inherit from InputMethodService, your keyboard will be available for other apps. There is only one way to create in-app keyboard, it is using simple View in your layout. In this example custom in-app keyboard they use InputMethodManager to connect to EditText.

vmtrue
  • 1,724
  • 18
  • 36
  • Sorry, First time I was wrong and didn't understand your question. I've updated my answer. – vmtrue Sep 04 '17 at 14:45
  • The example you linked to is my example. It doesn't use `InputMethodManager` to connect to `EditText`. It just connects it directly. But I wanted to use the `InputMethodManager`, which is what led to this question here. – Suragch Sep 04 '17 at 14:54
  • @Suragch Without inheriting from InputMethodManager you can't get access to keyboard – vmtrue Sep 05 '17 at 04:16