Sdílet prostřednictvím


InputMethodManager Class

Definition

Central system API to the overall input method framework (IMF) architecture, which arbitrates interaction between applications and the current input method.

[Android.Runtime.Register("android/view/inputmethod/InputMethodManager", DoNotGenerateAcw=true)]
public sealed class InputMethodManager : Java.Lang.Object
[<Android.Runtime.Register("android/view/inputmethod/InputMethodManager", DoNotGenerateAcw=true)>]
type InputMethodManager = class
    inherit Object
Inheritance
InputMethodManager
Attributes

Remarks

Central system API to the overall input method framework (IMF) architecture, which arbitrates interaction between applications and the current input method.

Topics covered here: <ol> <li>Architecture Overview<li>Applications<li>Input Methods<li>Security</ol>

"ArchitectureOverview"><h3>Architecture Overview</h3>

There are three primary parties involved in the input method framework (IMF) architecture:

<ul> <li> The <strong>input method manager</strong> as expressed by this class is the central point of the system that manages interaction between all other parts. It is expressed as the client-side API here which exists in each application context and communicates with a global system service that manages the interaction across all processes. <li> An <strong>input method (IME)</strong> implements a particular interaction model allowing the user to generate text. The system binds to the current input method that is in use, causing it to be created and run, and tells it when to hide and show its UI. Only one IME is running at a time. <li> Multiple <strong>client applications</strong> arbitrate with the input method manager for input focus and control over the state of the IME. Only one such client is ever active (working with the IME) at a time. </ul>

"Applications"><h3>Applications</h3>

In most cases, applications that are using the standard android.widget.TextView or its subclasses will have little they need to do to work well with soft input methods. The main things you need to be aware of are:

<ul> <li> Properly set the android.R.attr#inputType in your editable text views, so that the input method will have enough context to help the user in entering text into them. <li> Deal well with losing screen space when the input method is displayed. Ideally an application should handle its window being resized smaller, but it can rely on the system performing panning of the window if needed. You should set the android.R.attr#windowSoftInputMode attribute on your activity or the corresponding values on windows you create to help the system determine whether to pan or resize (it will try to determine this automatically but may get it wrong). <li> You can also control the preferred soft input state (open, closed, etc) for your window using the same android.R.attr#windowSoftInputMode attribute. </ul>

More finer-grained control is available through the APIs here to directly interact with the IMF and its IME -- either showing or hiding the input area, letting the user pick an input method, etc.

For the rare people amongst us writing their own text editors, you will need to implement android.view.View#onCreateInputConnection to return a new instance of your own InputConnection interface allowing the IME to interact with your editor.

"InputMethods"><h3>Input Methods</h3>

An input method (IME) is implemented as a android.app.Service, typically deriving from android.inputmethodservice.InputMethodService. It must provide the core InputMethod interface, though this is normally handled by android.inputmethodservice.InputMethodService and implementors will only need to deal with the higher-level API there.

See the android.inputmethodservice.InputMethodService class for more information on implementing IMEs.

"Security"><h3>Security</h3>

There are a lot of security issues associated with input methods, since they essentially have freedom to completely drive the UI and monitor everything the user enters. The Android input method framework also allows arbitrary third party IMEs, so care must be taken to restrict their selection and interactions.

Here are some key points about the security architecture behind the IMF:

<ul> <li>

Only the system is allowed to directly access an IME's InputMethod interface, via the android.Manifest.permission#BIND_INPUT_METHOD permission. This is enforced in the system by not binding to an input method service that does not require this permission, so the system can guarantee no other untrusted clients are accessing the current input method outside of its control.

<li>

There may be many client processes of the IMF, but only one may be active at a time. The inactive clients can not interact with key parts of the IMF through the mechanisms described below.

<li>

Clients of an input method are only given access to its InputMethodSession interface. One instance of this interface is created for each client, and only calls from the session associated with the active client will be processed by the current IME. This is enforced by android.inputmethodservice.AbstractInputMethodService for normal IMEs, but must be explicitly handled by an IME that is customizing the raw InputMethodSession implementation.

<li>

Only the active client's InputConnection will accept operations. The IMF tells each client process whether it is active, and the framework enforces that in inactive processes calls on to the current InputConnection will be ignored. This ensures that the current IME can only deliver events and text edits to the UI that the user sees as being in focus.

<li>

An IME can never interact with an InputConnection while the screen is off. This is enforced by making all clients inactive while the screen is off, and prevents bad IMEs from driving the UI when the user can not be aware of its behavior.

<li>

A client application can ask that the system let the user pick a new IME, but can not programmatically switch to one itself. This avoids malicious applications from switching the user to their own IME, which remains running when the user navigates away to another application. An IME, on the other hand, <em>is</em> allowed to programmatically switch the system to another IME, since it already has full control of user input.

<li>

The user must explicitly enable a new IME in settings before they can switch to it, to confirm with the system that they know about it and want to make it available for use.

</ul>

If your app targets Android 11 (API level 30) or higher, the methods in this class each return a filtered result by the rules of package visibility, except for the currently connected IME. Apps having a query for the InputMethod#SERVICE_INTERFACE see all IMEs.

Java documentation for android.view.inputmethod.InputMethodManager.

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.

Fields

ShowForced

Flag for #showSoftInput to indicate that the user has forced the input method open (such as by long-pressing menu) so it should not be closed until they explicitly do so.

ShowImplicit
Obsolete.

Flag for #showSoftInput to indicate that this is an implicit request to show the input window, not as the result of a direct request by the user.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
CurrentInputMethodInfo

Returns the InputMethodInfo of the currently selected input method (for the process's user).

CurrentInputMethodSubtype

Returns the current input method subtype.

EnabledInputMethodList

Returns the list of enabled input methods.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
InputMethodList

Returns the list of installed input methods.

IsAcceptingText

Return true if the currently served view is accepting full text edits.

IsActive

Return true if any view is currently active for the input method.

IsFullscreenMode

Allows you to discover whether the attached input method is running in fullscreen mode.

IsInputMethodSuppressingSpellChecker

Return true if the input method is suppressing system spell checker.

IsStylusHandwritingAvailable

Returns true if currently selected IME supports Stylus handwriting & is enabled.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
LastInputMethodSubtype

Returns the last used InputMethodSubtype in system history.

PeerReference (Inherited from Object)
ShortcutInputMethodsAndSubtypes

Returns a map of all shortcut input method info and their subtypes.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)

Methods

AcceptStylusHandwritingDelegation(View, String)

Accepts and starts a stylus handwriting session on the delegate view, if handwriting initiation delegation was previously requested using #prepareStylusHandwritingDelegation(View, String) from te delegator and the view belongs to a specified delegate package.

AcceptStylusHandwritingDelegation(View)

Accepts and starts a stylus handwriting session on the delegate view, if handwriting initiation delegation was previously requested using #prepareStylusHandwritingDelegation(View) from the delegator.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
DispatchKeyEventFromInputMethod(View, KeyEvent)

Provides the default implementation of InputConnection#sendKeyEvent(KeyEvent), which is expected to dispatch an keyboard event sent from the IME to an appropriate event target depending on the given View and the current focus state.

DisplayCompletions(View, CompletionInfo[])
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
FromContext(Context)
GetEnabledInputMethodSubtypeList(InputMethodInfo, Boolean)

Returns a list of enabled input method subtypes for the specified input method info.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
HideSoftInputFromInputMethod(IBinder, HideSoftInputFlags)

Close/hide the input method's soft input area, so the user no longer sees it or can interact with it.

HideSoftInputFromWindow(IBinder, HideSoftInputFlags, ResultReceiver)

Request to hide the soft input window from the context of the window that is currently accepting input.

HideSoftInputFromWindow(IBinder, HideSoftInputFlags)

Synonym for #hideSoftInputFromWindow(IBinder, int, ResultReceiver) without a result: request to hide the soft input window from the context of the window that is currently accepting input.

HideStatusIcon(IBinder)

This member is deprecated.

InvalidateInput(View)

Gives a hint to the system that the text associated with view is updated by something that is not an input method editor (IME), so that the system can cancel any pending text editing requests from the IME until it receives the new editing context such as surrounding text provided by InputConnection#takeSnapshot().

InvokeIsActive(View)

Return true if the given view is the currently active view for the input method.

IsWatchingCursor(View)
Obsolete.

Return true if the current input method wants to watch the location of the input editor's cursor in its window.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
PrepareStylusHandwritingDelegation(View, String)

Prepares delegation of starting stylus handwriting session to a different editor in same or a different window in a different package than the view on which initial handwriting stroke was detected.

PrepareStylusHandwritingDelegation(View)

Prepares delegation of starting stylus handwriting session to a different editor in same or different window than the view on which initial handwriting stroke was detected.

RestartInput(View)

If the input method is currently connected to the given view, restart it with its new contents.

SendAppPrivateCommand(View, String, Bundle)

Call InputMethodSession#appPrivateCommand(String, Bundle) InputMethodSession.appPrivateCommand() on the current Input Method.

SetAdditionalInputMethodSubtypes(String, InputMethodSubtype[])

Set additional input method subtypes.

SetCurrentInputMethodSubtype(InputMethodSubtype)

Switch to a new input method subtype of the current input method.

SetExplicitlyEnabledInputMethodSubtypes(String, Int32[])

Updates the list of explicitly enabled InputMethodSubtype for a given IME owned by the calling process.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetInputMethod(IBinder, String)

Force switch to a new input method component.

SetInputMethodAndSubtype(IBinder, String, InputMethodSubtype)

Force switch to a new input method and subtype.

ShouldOfferSwitchingToNextInputMethod(IBinder)

Returns true if the current IME needs to offer the users ways to switch to a next input method (e.

ShowInputMethodAndSubtypeEnabler(String)

Show the settings for enabling subtypes of the specified input method.

ShowInputMethodPicker()

Show IME picker popup window.

ShowSoftInput(View, ShowFlags, ResultReceiver)

Explicitly request that the current input method's soft input area be shown to the user, if needed.

ShowSoftInput(View, ShowFlags)

Synonym for #showSoftInput(View, int, ResultReceiver) without a result receiver: explicitly request that the current input method's soft input area be shown to the user, if needed.

ShowSoftInputFromInputMethod(IBinder, ShowFlags)

Show the input method's soft input area, so the user sees the input method window and can interact with it.

ShowStatusIcon(IBinder, String, Int32)

This member is deprecated.

StartStylusHandwriting(View)

Start stylus handwriting session.

SwitchToLastInputMethod(IBinder)

Force switch to the last used input method and subtype.

SwitchToNextInputMethod(IBinder, Boolean)

Force switch to the next input method and subtype.

ToArray<T>() (Inherited from Object)
ToggleSoftInput(ShowFlags, HideSoftInputFlags)

This method toggles the input method window display.

ToggleSoftInputFromWindow(IBinder, ShowSoftInputFlags, HideSoftInputFlags)

This method toggles the input method window display.

ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
UpdateCursor(View, Int32, Int32, Int32, Int32)
Obsolete.

Report the current cursor location in its window.

UpdateCursorAnchorInfo(View, CursorAnchorInfo)

Report positional change of the text insertion point and/or characters in the composition string.

UpdateExtractedText(View, Int32, ExtractedText)
UpdateSelection(View, Int32, Int32, Int32, Int32)

Report the current selection range.

ViewClicked(View)

Notify the event when the user tapped or clicked the text view.

Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to