Code example for ExtractedTextRequest

    private static int getCursorPosition(InputConnection connection) {
        if (null == connection) return INVALID_CURSOR_POSITION;
        ExtractedText extracted = connection.getExtractedText(
            new ExtractedTextRequest(), 0);
        if (extracted == null) {
            return INVALID_CURSOR_POSITION;
        return extracted.startOffset + extracted.selectionStart;
     * @param connection connection to the current text field. 
     * @param separators characters which may separate words 
     * @return the word that surrounds the cursor, including up to one trailing 
     *   separator. For example, if the field contains "he|llo world", where | 
     *   represents the cursor, then "hello " will be returned. 
    public static String getWordAtCursor(InputConnection connection, String separators) {
Experience pair programming with AI  Get Codota for Java