Code example for InputConnection

Methods: getExtractedText

0
        connection.setComposingText(text, 1);
    } 
 
    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) {