Share via


InputMethod.AccessibilityInputConnection.GetSurroundingText 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;", "", ApiSince=33)]
public Android.Views.InputMethods.SurroundingText? GetSurroundingText (int beforeLength, int afterLength, int flags);
[<Android.Runtime.Register("getSurroundingText", "(III)Landroid/view/inputmethod/SurroundingText;", "", ApiSince=33)>]
member 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 InputConnection#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 InputConnection#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>Accessibility service authors:</strong> please consider this will trigger an IPC round-trip that will take some time. Assume this method consumes a lot of time.

Java documentation for android.accessibilityservice.InputMethod.AccessibilityInputConnection.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