InputConnectionCompat

Added in 1.1.0

class InputConnectionCompat


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

Summary

Nested types

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

Constants

const 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 function is deprecated.

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

Public functions

java-static Boolean
commitContent(
    inputConnection: InputConnection,
    editorInfo: EditorInfo,
    inputContentInfo: InputContentInfoCompat,
    flags: Int,
    opts: Bundle?
)

Calls commitContent API, in a backwards compatible fashion.

java-static InputConnection
createWrapper(
    inputConnection: InputConnection,
    editorInfo: EditorInfo,
    onCommitContentListener: InputConnectionCompat.OnCommitContentListener
)

This function is deprecated.

Use and { } instead.

java-static InputConnection
createWrapper(
    view: View,
    inputConnection: InputConnection,
    editorInfo: EditorInfo
)

Creates a wrapper InputConnection that implements InputConnection's features on past versions of Android.

Constants

INPUT_CONTENT_GRANT_READ_URI_PERMISSION

Added in 1.1.0
const val INPUT_CONTENT_GRANT_READ_URI_PERMISSION = 1: 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 ContentProvider.

Public constructors

InputConnectionCompat

Added in 1.1.0
Deprecated in 1.1.0
InputConnectionCompat()

Public functions

commitContent

Added in 1.1.0
java-static fun commitContent(
    inputConnection: InputConnection,
    editorInfo: EditorInfo,
    inputContentInfo: InputContentInfoCompat,
    flags: Int,
    opts: Bundle?
): Boolean

Calls commitContent API, in a backwards compatible fashion.

Parameters
inputConnection: InputConnection

InputConnection with which commitContent API will be called

editorInfo: EditorInfo

EditorInfo associated with the given inputConnection

inputContentInfo: InputContentInfoCompat

content information to be passed to the editor

flags: Int

0 or INPUT_CONTENT_GRANT_READ_URI_PERMISSION

opts: Bundle?

optional bundle data. This can be null

Returns
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

Added in 1.1.0
Deprecated in 1.7.0
java-static fun createWrapper(
    inputConnection: InputConnection,
    editorInfo: EditorInfo,
    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 onCommitContent when the IME calls commitContent and the corresponding Framework API that is available on API >= 25.

Parameters
inputConnection: InputConnection

InputConnection to be wrapped

editorInfo: EditorInfo

EditorInfo associated with the given inputConnection

onCommitContentListener: InputConnectionCompat.OnCommitContentListener

the listener that the wrapper object will call

Returns
InputConnection

a wrapper InputConnection object that can be returned to the IME

Throws
java.lang.IllegalArgumentException

when inputConnection, editorInfo, or onCommitContentListener is null

createWrapper

Added in 1.7.0
java-static fun createWrapper(
    view: View,
    inputConnection: InputConnection,
    editorInfo: EditorInfo
): InputConnection

Creates a wrapper InputConnection that implements InputConnection's features on past versions of Android.

Currently, handles commitContent by dispatching to performReceiveContent, enabling apps to use setOnReceiveContentListener to specify handling for content insertion from the IME.

Usage:

public class MyWidget extends View {
    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        InputConnection ic = super.onCreateInputConnection(outAttrs);
        if (ic == null) {
            return ic;
        }
        String[] mimeTypes = ViewCompat.getOnReceiveContentMimeTypes(this);
        if (mimeTypes != null) {
            EditorInfoCompat.setContentMimeTypes(outAttrs, mimeTypes);
            ic = InputConnectionCompat.createWrapper(this, ic, outAttrs);
        }
        return ic;
    }
}
Parameters
view: View

The view that the given input connection is associated with.

inputConnection: InputConnection

The input connection to be wrapped.

editorInfo: EditorInfo

The editor metadata associated with the given input connection.

Returns
InputConnection

A wrapper InputConnection object that can be returned to the IME.