Android Webview Strategy For Deleting Images Causing Speech-To-Text to Fail

◇◆丶佛笑我妖孽 提交于 2021-01-28 07:07:28

问题


Problem: Can't delete image in contenteditable div on Android

Only known solution at the moment: Android: Backspace in WebView/BaseInputConnection

Problem with solution: Setting: creating a BaseInputConnection using the regular constructor seems to disable speech to text from functioning correctly. as opposed to using WebView.onCreateInputConnection(EditorInfo) to generate an InputConnection.

any ideas how to remedy this?


回答1:


I had the same issue also with text completion using SwiftKey. In order to fix it you must remember some things:

  • you must extend BaseInputConnection and wrap the original webview's InputConnection
  • don't use InputConnectionWrapper as it will cause other problems
  • you need to subclass a second method: commitText

    public boolean commitText(CharSequence text, int newCursorPosition) {
    
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            return orig.commitText(text, newCursorPosition);
    
        } else {
            // pre-kitkat workaround 
            boolean res = true;
            for (int i = 0; i < text.length(); i++) {
                res = orig.commitText(text.subSequence(i, i+1), newCursorPosition);
            }
            return res;
        }
    }
    


来源:https://stackoverflow.com/questions/24704540/android-webview-strategy-for-deleting-images-causing-speech-to-text-to-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!