IInputConnectionExtensions.GetSelectedText Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the selected text, if any.
public static string? GetSelectedText(this Android.Views.InputMethods.IInputConnection self, Android.Views.InputMethods.GetTextFlags flags);
static member GetSelectedText : Android.Views.InputMethods.IInputConnection * Android.Views.InputMethods.GetTextFlags -> string
Parameters
- self
- IInputConnection
The input connection on which to call the method.
- flags
- GetTextFlags
Either None or WithStyles.
Returns
The selected text, or null if no text is selected or the request fails.
Remarks
Gets the selected text, if any.
This method may fail if either 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 of seconds to return). In either case, null is returned.
This method must not cause any changes in the editor's state.
If WithStyles is supplied, the editor should return a SpannableString with the text's spans. This extension converts that result to a string without the spans. To access any returned spans, call GetSelectedTextFormatted(GetTextFlags).
Input method authors: this call can take time because it involves interprocess communication. To get initial text around the cursor without that cost, consider GetInitialTextBeforeCursor(Int32, Int32), GetInitialSelectedText(Int32), and GetInitialTextAfterCursor(Int32, Int32).
Editor authors: please be careful of race conditions in implementing this call. An IME can make a change to the text or change the selection position and use this method right away; you need to make sure the returned value is consistent with the results of the latest edits.
Android reference for android.view.inputmethod.InputConnection.getSelectedText.
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.