Code example for InputConnection

Methods: beginBatchEditcommitTextdeleteSurroundingTextendBatchEditgetExtractedText

0
            Log.i(TAG, "Unable to commit recognition result, as the current input connection "
                    + "is null. Did someone kill the IME?"); 
            return; 
        } 
 
        if (!conn.beginBatchEdit()) {
            Log.i(TAG, "Unable to commit recognition result, as a batch edit cannot start");
            return; 
        } 
 
        try { 
            ExtractedTextRequest etr = new ExtractedTextRequest();
            etr.flags = InputConnection.GET_TEXT_WITH_STYLES;
 
            ExtractedText et = conn.getExtractedText(etr, 0);
 
            if (et == null) {
                Log.i(TAG, "Unable to commit recognition result, as extracted text is null");
                return; 
            } 
 
            if (et.text != null) {
 
                if (et.selectionStart != et.selectionEnd) {
                    conn.deleteSurroundingText(et.selectionStart, et.selectionEnd);
                } 
 
                result = format(et, result);
            } 
 
            if (!conn.commitText(result, 0)) {
                Log.i(TAG, "Unable to commit recognition result");
                return; 
            } 
 
            mLastRecognitionResult = null;
        } finally { 
            conn.endBatchEdit();
        } 
    } 
 
    /** 
     * Formats the recognised text by adding white spaces at the beginning or at the end, and 
Stop searching for code, let great code find you!  Add Codota to your java IDE