3

The showSoftInputFromInputMethod method from the InputMethodManager class is deprecated in Android P. As per the documentation, we should be using the InputMethodService.requestShowSelf(int) method for Android P and above.

Now the question is how can we get the reference for the class InputMethodService. I tried creating a new object and calling requestShowself() on it but it doesn't work.

InputMethodService inputMethodService = new InputMethodService();
inputMethodService.requestShowSelf(0);

How can we use the suggested alternative for this deprecation for API 28 and above?

BDL
  • 21,052
  • 22
  • 49
  • 55
Amrut
  • 2,655
  • 3
  • 24
  • 44

2 Answers2

4

InputMethodService is implemented by IME apps. (e.g. gboard). If you're app developer and trying to show IME, use InputMethodManager.showSoftInput(TextView, 0);

Taranfx
  • 10,361
  • 17
  • 77
  • 95
3

Kotlin version:

    fun showKeyboard(mEtSearch: EditText, context: Context) {
            mEtSearch.requestFocus()
            val imm: InputMethodManager =
                context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.showSoftInput(mEtSearch, 0)
    }
Akshay
  • 73
  • 8