Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView HTML input keypress doesn't fire

On some devices (mostly Samsung, but others too) and combinations of: Android version, WebView version (even with the evergreen WebView in Android 7) and keyboard, there are a number of issues:

  • keypress isn't fired
  • keydown and keyup always contain keyCode=229
  • keypress and input are fired but don't contain the key
  • textInput isn't fired
  • maxlength attribute isn't honored on input[type=text] while the user types (more than maxlength chars are allowed and the input is validated only when the form is submitted)

Is there a way to fix these issues?

like image 384
gabrielmaldi Avatar asked Jul 25 '17 20:07

gabrielmaldi


1 Answers

I found that if you extend WebView and override onCreateInputConnection, all of those issues are fixed:

public class WebViewExtended extends WebView {
    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        // This line fixes some issues but introduces others, YMMV.
        // super.onCreateInputConnection(outAttrs);

        return new BaseInputConnection(this, false);
    }
}

Before overriding onCreateInputConnection:

before

After overriding onCreateInputConnection (g was pressed):

after

like image 57
gabrielmaldi Avatar answered Oct 30 '22 14:10

gabrielmaldi