Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

InputConnectionCompat

class InputConnectionCompat
kotlin.Any
   ↳ androidx.core.view.inputmethod.InputConnectionCompat

Helper for accessing features in InputConnection introduced after API level 13 in a backwards compatible fashion.

Summary

Nested classes
abstract

Listener for commitContent method call, in a backwards compatible fashion.

Constants
static Int

When this flag is used, the editor will be able to request temporary access permissions to the content URI contained in the InputContentInfoCompat object, in a similar manner that has been recommended in Sharing Files.

Public constructors

This type should not be instantiated as it contains only static methods.

Public methods
static Boolean
commitContent(@NonNull inputConnection: InputConnection, @NonNull editorInfo: EditorInfo, @NonNull inputContentInfo: InputContentInfoCompat, flags: Int, @Nullable opts: Bundle?)

Calls commitContent API, in a backwards compatible fashion.

static InputConnection
createWrapper(@NonNull inputConnection: InputConnection, @NonNull editorInfo: EditorInfo, @NonNull onCommitContentListener: InputConnectionCompat.OnCommitContentListener)

Creates a wrapper InputConnection object from an existing InputConnection and OnCommitContentListener that can be returned to the system.

Constants

INPUT_CONTENT_GRANT_READ_URI_PERMISSION

static val INPUT_CONTENT_GRANT_READ_URI_PERMISSION: Int

When this flag is used, the editor will be able to request temporary access permissions to the content URI contained in the InputContentInfoCompat object, in a similar manner that has been recommended in Sharing Files.

Make sure that the content provider owning the Uri sets the grantUriPermissions attribute in its manifest or included the <grant-uri-permissions> tag.

Supported only on API >= 25.

On API <= 24 devices, IME developers need to ensure that the content URI is accessible only from the target application, for example, by generating a URL with a unique name that others cannot guess. IME developers can also rely on the following information of the target application to do additional access checks in their android.content.ContentProvider.

Value: 0x00000001

Public constructors

<init>

InputConnectionCompat()

Deprecated: This type should not be instantiated as it contains only static methods.

Public methods

commitContent

static fun commitContent(@NonNull inputConnection: InputConnection, @NonNull editorInfo: EditorInfo, @NonNull inputContentInfo: InputContentInfoCompat, flags: Int, @Nullable opts: Bundle?): Boolean

Calls commitContent API, in a backwards compatible fashion.

Parameters
inputConnection InputConnection: InputConnection with which commitContent API will be called
editorInfo InputConnection: EditorInfo associated with the given inputConnection
inputContentInfo InputConnection: content information to be passed to the editor
flags InputConnection: 0 or INPUT_CONTENT_GRANT_READ_URI_PERMISSION
opts InputConnection: optional bundle data. This can be null
Return
Boolean: true if this request is accepted by the application, no matter if the request is already handled or still being handled in background

createWrapper

@NonNull static fun createWrapper(@NonNull inputConnection: InputConnection, @NonNull editorInfo: EditorInfo, @NonNull onCommitContentListener: InputConnectionCompat.OnCommitContentListener): InputConnection

Creates a wrapper InputConnection object from an existing InputConnection and OnCommitContentListener that can be returned to the system.

By returning the wrapper object to the IME, the editor can be notified by OnCommitContentListener#onCommitContent(InputContentInfoCompat, int, Bundle) when the IME calls InputConnectionCompat#commitContent(InputConnection, EditorInfo, * InputContentInfoCompat, int, Bundle) and the corresponding Framework API that is available on API >= 25.

Parameters
inputConnection InputConnection: InputConnection to be wrapped
editorInfo InputConnection: EditorInfo associated with the given inputConnection
onCommitContentListener InputConnection: the listener that the wrapper object will call
Return
InputConnection: a wrapper InputConnection object that can be returned to the IME
Exceptions
IllegalArgumentException when inputConnection, editorInfo, or onCommitContentListener is null