InputConnectionCompat
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 |
Public constructors |
|---|
|
This function is deprecated. This type should not be instantiated as it contains only static methods. |
Public functions |
|
|---|---|
java-static Boolean |
commitContent(Calls commitContent API, in a backwards compatible fashion. |
java-static InputConnection |
This function is deprecated. Use |
java-static InputConnection |
createWrapper(Creates a wrapper |
Constants
INPUT_CONTENT_GRANT_READ_URI_PERMISSION
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.
- On API >= 23
packageNameis guaranteed to not be spoofed, which can later be compared withgetCallingPackagein theContentProvider. getUidis guaranteed to not be spoofed, which can later be compared withgetCallingUidin theContentProvider.
Public constructors
Public functions
commitContent
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 |
|
editorInfo: EditorInfo |
|
inputContentInfo: InputContentInfoCompat |
content information to be passed to the editor |
flags: Int |
|
opts: Bundle? |
optional bundle data. This can be |
| Returns | |
|---|---|
Boolean |
|
java-static funcreateWrapper(
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 |
|
editorInfo: EditorInfo |
|
onCommitContentListener: InputConnectionCompat.OnCommitContentListener |
the listener that the wrapper object will call |
| Returns | |
|---|---|
InputConnection |
a wrapper |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
when |
createWrapper
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 |