Code example for InputConnection

Methods: getExtractedText

        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. 
Stop searching for code, let great code find you!  Add Codota to your java IDE