InputConnectionCompat
public final class InputConnectionCompat
Helper for accessing features in InputConnection introduced after API level 13 in a backwards compatible fashion.
Summary
Nested types |
|---|
public interface InputConnectionCompat.OnCommitContentListenerListener for commitContent method call, in a backwards compatible fashion. |
Constants |
|
|---|---|
static final 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 method is deprecated. This type should not be instantiated as it contains only static methods. |
Public methods |
|
|---|---|
static boolean |
commitContent(Calls commitContent API, in a backwards compatible fashion. |
static @NonNull InputConnection |
This method is deprecated. Use |
static @NonNull InputConnection |
createWrapper(Creates a wrapper |
Constants
INPUT_CONTENT_GRANT_READ_URI_PERMISSION
public static final int INPUT_CONTENT_GRANT_READ_URI_PERMISSION = 1
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 methods
commitContent
public static boolean commitContent(
@NonNull InputConnection inputConnection,
@NonNull EditorInfo editorInfo,
@NonNull InputContentInfoCompat inputContentInfo,
int flags,
@Nullable Bundle opts
)
Calls commitContent API, in a backwards compatible fashion.
| Parameters | |
|---|---|
@NonNull InputConnection inputConnection |
|
@NonNull EditorInfo editorInfo |
|
@NonNull InputContentInfoCompat inputContentInfo |
content information to be passed to the editor |
int flags |
|
@Nullable Bundle opts |
optional bundle data. This can be |
| Returns | |
|---|---|
boolean |
|
public static @NonNull InputConnectioncreateWrapper(
@NonNull InputConnection inputConnection,
@NonNull EditorInfo editorInfo,
@NonNull InputConnectionCompat.OnCommitContentListener onCommitContentListener
)
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 | |
|---|---|
@NonNull InputConnection inputConnection |
|
@NonNull EditorInfo editorInfo |
|
@NonNull InputConnectionCompat.OnCommitContentListener onCommitContentListener |
the listener that the wrapper object will call |
| Returns | |
|---|---|
@NonNull InputConnection |
a wrapper |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
when |
createWrapper
public static @NonNull InputConnection createWrapper(
@NonNull View view,
@NonNull InputConnection inputConnection,
@NonNull EditorInfo editorInfo
)
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 | |
|---|---|
@NonNull View view |
The view that the given input connection is associated with. |
@NonNull InputConnection inputConnection |
The input connection to be wrapped. |
@NonNull EditorInfo editorInfo |
The editor metadata associated with the given input connection. |
| Returns | |
|---|---|
@NonNull InputConnection |
A wrapper |