Android 12 ignoring showSoftInput as VIEW is not served

2.8k Views Asked by At

My app worked fine for lots of devices. But since upgrading to Android 12 on my own Pixel the following happens when calling showSoftInput or just when tapping the AppCompatEditText in a Bottomsheet.

val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager;
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)

Logcat warning (nothing happens in the app):

Ignoring showSoftInput() as view=androidx.appcompat.widget.AppCompatEditText{b5311a0 VFED..CL. .F.P..ID 84,0-996,118 #7f0900a7 app:id/et_bottomsheet aid=1073741827} is not served.

I tried lots of things like requesting focus, showSoftInput with SHOW_FORCE but nothing worked.

2

There are 2 best solutions below

0
Merthan Erdem On BEST ANSWER

Solution: The problem seems to be that the keyboard couldn't gain window focus?

Anyways, the parts that were causing problems were:

window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)

window?.decorView?.systemUiVisibility = fullscreenFlags

and

private const val fullscreenFlags = (View.SYSTEM_UI_FLAG_FULLSCREEN
        or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_IMMERSIVE
        or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)

I removed them for now on SDK 33+, which kind of breaks the hiding of navigation elements that I had before but it's the only way I could fix this quickly. Now everything seems to work.

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) doThose()
4
Zain On

Starting from Android 11 (API 30) you can manually force the ime/keyboard to show with inset's API show()

myAppCompatEditText.windowInsetsController.show(WindowInsetsCompat.Type.ime())

And hide it with:

myAppCompatEditText.windowInsetsController.hide(WindowInsetsCompat.Type.ime())

To targed APIs below API 30, This is backported using the Compat version:

WindowInsetsControllerCompat(window, myAppCompatEditText)
                                     .show(WindowInsetsCompat.Type.ime())

WindowInsetsControllerCompat(window, myAppCompatEditText)
                                     .hide(WindowInsetsCompat.Type.ime())