I want to type special characters (such as 'ä', 'é', '£', etc.) in an Android webview. These characters are not included into the virtual KCM (key characters map). So I can't retrieve the keycode associated to the character and create a KeyEvent.
I tried different methods:
String t = "testàaâäù"; char[] charArray = t.toCharArray(); if (charArray.length > 0) { KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); KeyEvent[] events = keyCharacterMap.getEvents(charArray); } // events is null, because some characters aren't include in KCM // it never works in any case With instrumentation methods:
instrumentation.sendStringSync("a"); // Display 'a' instrumentation.sendStringSync("àâä"); // Display nothing instrumentation.sendCharacterSync(KeyEvent.KEYCODE_H); // Display 'h' // Instrumentation seems to use KCM for data entry With ACTION_MULTIPLE KeyEvent:
KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(), String.valueOf("aàâä"), 0, 0); focusedView.dispatchKeyEvent(event); // Doesn't work with WebView, but works with other components such as EditText. // I get this error: Unimplemented WebView method onKeyMultiple called from: android.webkit.WebView.onKeyMultiple Can I implement the method onKeyMultiple (WebView) to handle data entry? Is there a solution for inputting special characters in the webview? I need a solution that doesn't require root or the creation of a keyboard layout (user hasn't to select the keyboard).