I've written an IME (InputMethodService) and I need to get all the text from the EditText it is editing. I know one way:
InputConnection inputConnection = getCurrentInputConnection();
inputConnection.append(inputConnection.getTextBeforeCursor(9999, 0))
.append(inputConnection.getTextAfterCursor(9999, 0));
It works, but it seems pretty stupid and clunky. However there is no such method InputConnection.getText()
.
Is there a better way?
P.S. I cannot access the EditText from my IME because it belongs to the parent app so please don't tell me to use EditText.getText(), unless you know a way to get the EditText!
getTextBeforeCursor
andgetTextAfterCursor
do not include the selected text (if there is a selection). – Conveyor