1

I extended InputMethodService hoping to use this Service for showing a soft keyboard even though a hard keyboard is connected(based off the following post Show soft keyboard even though a hardware keyboard is connected). Is there a way to bind to this service within the app without having to declare it in the manifest? The end result is to have InputMethodService.onEvaluateInputViewShown return true so that the soft keyboard will show even though a hard keyboard is connected.

I would like to use the extended class MultiInputMethodService with the inputmethodmanager in show/hideSoftKeyboard:

public class MultiInputMethodService extends InputMethodService {

        @Override
        public boolean onEvaluateInputViewShown () {
            Log.i("onEvaluateInputViewShow","onEvaluateInputViewShown");
             return true;
        }   
}

my activity:

 private void showSoftKeyboard() {
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY );
    }

    private void hideSoftKeyboard() {
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(this.myInput.getEditText().getWindowToken(), 0);
    }
Community
  • 1
  • 1
prostock
  • 9,327
  • 19
  • 70
  • 118

1 Answers1

0

The IMS framework really needs to be used as a whole. If you want to be the keyboard, the user will need to select you as the default keyboard via settings. If you were to try to bind with the service directly I'm not sure what the result would be, but my guess would be that it ends badly. By having the user set you as the default keyboard, you will automatically be used as the keyboard in all apps.

Of course, you can't just set that yourself, for security purposes. Otherwise keyboards would be fighting over the setting. The user has to set it manually.

EDIT: I found the documentation you are referring to(under the "Security Section"):

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html

A client application can ask that the system let the user pick a new IME, but can not programmatically switch to one itself. This avoids malicious applications from switching the user to their own IME, which remains running when the user navigates away to another application. An IME, on the other hand, is allowed to programmatically switch the system to another IME, since it already has full control of user input.

The user must explicitly enable a new IME in settings before they can switch to it, to confirm with the system that they know about it and want to make it available for use.

prostock
  • 9,327
  • 19
  • 70
  • 118
Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127