Is there a way to tell if the soft-keyboard is shown?

is there a way to tell if the softkeyboard is shown in an activity or not?

I tried

InputMethodManager manager = (InputMethodManager) 
getSystemService(getApplicationContext().INPUT_METHOD_SERVICE);
manager.isActive(v)

but isActive returns false only before the first time the keyboard is shown, but if the kb appears and then dismissed, isActive returns true also.

so is there any other method to check for this issue.

thanks


According to this POST

You cannot detect if soft keyboard is shown or not, but you can indirectly know that a soft key board is shown by knowing that the View of your activity is resized.

Imagine you have a ListView and at the bottom an EditText, you want to go to the bottom of the list when a soft keyboard is shown after user clicks the EditText.

You need to implement a subclass of ListView, then use it in your ListActivity or Activity or View.

public class ThreadView extends ListView {

    public ThreadView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    @Override
    protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) {
        super.onSizeChanged(xNew, yNew, xOld, yOld);

        if (yOld > yNew) {
            setSelection(((ListAdapter) getAdapter()).getCount() - 1);
        }
    }
}

Hope this helps

PS. "check Configuration Changes" only works for hand keyboard.


You can detect the state AND coordinates of the software keyboard, using dumpsys shell command.

Because dumpsys requires permission.android.DUMP, which is a system application permission, you have two options: 1. use a rooted device to grant this permission. 2. override the problem using adb as described in my other answer.

Now, run the following command: dumpsys window InputMethod | grep "mHasSurface" to get the data you are looking for.