See Also: InputConnection Members
The InputConnection interface is the communication channel from an Android.Views.InputMethods.InputMethod back to the application that is receiving its input. It is used to perform such things as reading text around the cursor, committing text to the text box, and sending raw key events to the application.
Applications should never directly implement this interface, but instead subclass from Android.Views.InputMethods.BaseInputConnection. This will ensure that the application does not break when new methods are added to the interface.
Text input is the result of the synergy of two essential components: an Input Method Engine (IME) and an editor. The IME can be a software keyboard, a handwriting interface, an emoji palette, a speech-to-text engine, and so on. There are typically several IMEs installed on any given Android device. In Android, IMEs extend Android.InputMethodServices.InputMethodService. For more information about how to create an IME, see the Creating an input method guide. The editor is the component that receives text and displays it. Typically, this is an Android.Widget.EditText instance, but some applications may choose to implement their own editor for various reasons. This is a large and complicated task, and an application that does this needs to make sure the behavior is consistent with standard EditText behavior in Android. An editor needs to interact with the IME, receiving commands through this InputConnection interface, and sending commands through Android.Views.InputMethods.InputMethodManager. An editor should start by implementing Android.Views.View.OnCreateInputConnection(EditorInfo) to return its own input connection.
If you are implementing your own IME, you will need to call the methods in this interface to interact with the application. Be sure to test your IME with a wide range of applications, including browsers and rich text editors, as some may have peculiarities you need to deal with. Remember your IME may not be the only source of changes on the text, and try to be as conservative as possible in the data you send and as liberal as possible in the data you receive.
If you are implementing your own editor, you will probably need to provide your own subclass of Android.Views.InputMethods.BaseInputConnection to answer to the commands from IMEs. Please be sure to test your editor with as many IMEs as you can as their behavior can vary a lot. Also be sure to test with various languages, including CJK languages and right-to-left languages like Arabic, as these may have different input requirements. When in doubt about the behavior you should adopt for a particular call, please mimic the default TextView implementation in the latest Android version, and if you decide to drift from it, please consider carefully that inconsistencies in text editor behavior is almost universally felt as a bad thing by users.
In Android, the cursor and the selection are one and the same thing. A "cursor" is just the special case of a zero-sized selection. As such, this documentation uses them interchangeably. Any method acting "before the cursor" would act before the start of the selection if there is one, and any method acting "after the cursor" would act after the end of the selection.
An editor needs to be able to keep track of a currently "composing" region, like the standard edition widgets do. The composition is marked in a specific style: see Android.Text.ISpanned.SPAN_COMPOSING. IMEs use this to help the user keep track of what part of the text they are currently focusing on, and interact with the editor using InputConnection.setComposingText(java.lang.CharSequence, int), InputConnection.setComposingRegion(int, int) and InputConnection.finishComposingText(). The composing region and the selection are completely independent of each other, and the IME may use them however they see fit.