public final class InputConnectionCompat extends Object
InputConnection
introduced after API level 13 in a
backwards compatible fashion.Modifier and Type | Class and Description |
---|---|
static interface |
InputConnectionCompat.OnCommitContentListener
Listener for commitContent method call, in a backwards compatible fashion.
|
Modifier and Type | Field and Description |
---|---|
static int |
INPUT_CONTENT_GRANT_READ_URI_PERMISSION
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. |
Constructor and Description |
---|
InputConnectionCompat() |
Modifier and Type | Method and Description |
---|---|
static boolean |
commitContent(InputConnection inputConnection,
EditorInfo editorInfo,
InputContentInfoCompat inputContentInfo,
int flags,
Bundle opts)
Calls commitContent API, in a backwards compatible fashion.
|
static InputConnection |
createWrapper(InputConnection inputConnection,
EditorInfo editorInfo,
InputConnectionCompat.OnCommitContentListener onCommitContentListener)
Creates a wrapper
InputConnection object from an existing InputConnection
and InputConnectionCompat.OnCommitContentListener that can be returned to the system. |
public static int INPUT_CONTENT_GRANT_READ_URI_PERMISSION
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
.
EditorInfo.packageName
is guaranteed to not be spoofed, which
can later be compared with ContentProvider.getCallingPackage()
in
the ContentProvider
.
InputBinding.getUid()
is guaranteed to not be
spoofed, which can later be compared with Binder.getCallingUid()
in
the ContentProvider
.public static boolean commitContent(@NonNull InputConnection inputConnection, @NonNull EditorInfo editorInfo, @NonNull InputContentInfoCompat inputContentInfo, int flags, @Nullable Bundle opts)
inputConnection
- InputConnection
with which commitContent API will be callededitorInfo
- EditorInfo
associated with the given inputConnection
inputContentInfo
- content information to be passed to the editorflags
- 0
or INPUT_CONTENT_GRANT_READ_URI_PERMISSION
opts
- optional bundle data. This can be null
true
if this request is accepted by the application, no matter if the request
is already handled or still being handled in background@NonNull public static InputConnection createWrapper(@NonNull InputConnection inputConnection, @NonNull EditorInfo editorInfo, @NonNull InputConnectionCompat.OnCommitContentListener onCommitContentListener)
InputConnection
object from an existing InputConnection
and InputConnectionCompat.OnCommitContentListener
that can be returned to the system.
By returning the wrapper object to the IME, the editor can be notified by
InputConnectionCompat.OnCommitContentListener.onCommitContent(InputContentInfoCompat, int, Bundle)
when the IME calls
commitContent(InputConnection, EditorInfo,
InputContentInfoCompat, int, Bundle)
and the corresponding Framework API that is available
on API >= 25.
inputConnection
- InputConnection
to be wrappededitorInfo
- EditorInfo
associated with the given inputConnection
onCommitContentListener
- the listener that the wrapper object will callInputConnection
object that can be returned to the IMEIllegalArgumentException
- when inputConnection
, editorInfo
, or
onCommitContentListener
is null