Freigeben über


IInputConnection.GetSurroundingText(Int32, Int32, Int32) Method

Definition

Gets the surrounding text around the current cursor, with <var>beforeLength</var> characters of text before the cursor (start of the selection), <var>afterLength</var> characters of text after the cursor (end of the selection), and all of the selected text.

[Android.Runtime.Register("getSurroundingText", "(III)Landroid/view/inputmethod/SurroundingText;", "GetGetSurroundingText_IIIHandler:Android.Views.InputMethods.IInputConnection, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=31)]
public virtual Android.Views.InputMethods.SurroundingText? GetSurroundingText (int beforeLength, int afterLength, int flags);
[<Android.Runtime.Register("getSurroundingText", "(III)Landroid/view/inputmethod/SurroundingText;", "GetGetSurroundingText_IIIHandler:Android.Views.InputMethods.IInputConnection, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=31)>]
abstract member GetSurroundingText : int * int * int -> Android.Views.InputMethods.SurroundingText
override this.GetSurroundingText : int * int * int -> Android.Views.InputMethods.SurroundingText

Parameters

beforeLength
Int32

The expected length of the text before the cursor.

afterLength
Int32

The expected length of the text after the cursor.

flags
Int32

Supplies additional options controlling how the text is returned. May be either 0 or #GET_TEXT_WITH_STYLES.

Returns

an android.view.inputmethod.SurroundingText object describing the surrounding text and state of selection, or null if the input connection is no longer valid, or the editor can't comply with the request for some reason, or the application does not implement this method. The length of the returned text might be less than the sum of <var>beforeLength</var> and <var>afterLength</var> .

Attributes

Remarks

Gets the surrounding text around the current cursor, with <var>beforeLength</var> characters of text before the cursor (start of the selection), <var>afterLength</var> characters of text after the cursor (end of the selection), and all of the selected text. The range are for java characters, not glyphs that can be multiple characters.

This method may fail either if the input connection has become invalid (such as its process crashing), or the client is taking too long to respond with the text (it is given a couple seconds to return), or the protocol is not supported. In any of these cases, null is returned.

This method does not affect the text in the editor in any way, nor does it affect the selection or composing spans.

If #GET_TEXT_WITH_STYLES is supplied as flags, the editor should return a android.text.Spanned with all the spans set on the text.

<strong>IME authors:</strong> please consider this will trigger an IPC round-trip that will take some time. Assume this method consumes a lot of time. If you are using this to get the initial surrounding text around the cursor, you may consider using EditorInfo#getInitialTextBeforeCursor(int, int), EditorInfo#getInitialSelectedText(int), and EditorInfo#getInitialTextAfterCursor(int, int) to prevent IPC costs.

Java documentation for android.view.inputmethod.InputConnection.getSurroundingText(int, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to