androidandroid-edittextandroid-appcompatinputmethodmanager

Android 12 ignoring showSoftInput as VIEW is not served


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.


Solution

  • 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()