# InputConnectionCompat

# InputConnectionCompat

Artifact:[androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/view/inputmethod/InputConnectionCompat.java+class:androidx.core.view.inputmethod.InputConnectionCompat)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/view/inputmethod/InputConnectionCompat "View this page in Java")

<br />

```
class InputConnectionCompat
```

<br />

*** ** * ** ***

Helper for accessing features in[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)introduced after API level 13 in a backwards compatible fashion.

## Summary

|                                                                                                                          ### Nested types                                                                                                                           |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `interface `[InputConnectionCompat.OnCommitContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat.OnCommitContentListener) Listener for commitContent method call, in a backwards compatible fashion. |

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [INPUT_CONTENT_GRANT_READ_URI_PERMISSION](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#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](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputContentInfoCompat)object, in a similar manner that has been recommended in[Sharing Files](https://developer.android.com/training/secure-file-sharing). |

|                                                                                                                            ### Public constructors                                                                                                                            |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ~~[InputConnectionCompat](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#InputConnectionCompat())~~`()` **This function is deprecated.** This type should not be instantiated as it contains only static methods. <br /> |

|                                                  ### Public functions                                                  |
|------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                      | [commitContent](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#commitContent(android.view.inputmethod.InputConnection,android.view.inputmethod.EditorInfo,androidx.core.view.inputmethod.InputContentInfoCompat,int,android.os.Bundle))`(` ` inputConnection: `[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)`,` ` editorInfo: `[EditorInfo](https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html)`,` ` inputContentInfo: `[InputContentInfoCompat](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputContentInfoCompat)`,` ` flags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` opts: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`?` `)` Calls commitContent API, in a backwards compatible fashion.                                                                                               |
| `java-static `[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html) | ~~[createWrapper](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#createWrapper(android.view.inputmethod.InputConnection,android.view.inputmethod.EditorInfo,androidx.core.view.inputmethod.InputConnectionCompat.OnCommitContentListener))~~`(` ` inputConnection: `[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)`,` ` editorInfo: `[EditorInfo](https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html)`,` ` onCommitContentListener: `[InputConnectionCompat.OnCommitContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat.OnCommitContentListener) `)` **This function is deprecated.** Use[and { } instead.](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#createWrapper(android.view.View,android.view.inputmethod.InputConnection,android.view.inputmethod.EditorInfo)) <br /> |
| `java-static `[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html) | [createWrapper](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#createWrapper(android.view.View,android.view.inputmethod.InputConnection,android.view.inputmethod.EditorInfo))`(` ` view: `[View](https://developer.android.com/reference/android/view/View.html)`,` ` inputConnection: `[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)`,` ` editorInfo: `[EditorInfo](https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html) `)` Creates a wrapper[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)that implements`InputConnection`'s features on past versions of Android.                                                                                                                                                                                                                                                                        |

## Constants

### INPUT_CONTENT_GRANT_READ_URI_PERMISSION

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputContentInfoCompat)object, in a similar manner that has been recommended in[Sharing Files](https://developer.android.com/training/secure-file-sharing).

Make sure that the content provider owning the Uri sets the[grantUriPermissions](https://developer.android.com/reference/android/R.attr.html#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](https://developer.android.com/reference/android/content/ContentProvider.html).

- On API \>= 23[packageName](https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#packageName())is guaranteed to not be spoofed, which can later be compared with[getCallingPackage](https://developer.android.com/reference/android/content/ContentProvider.html#getCallingPackage())in the[ContentProvider](https://developer.android.com/reference/android/content/ContentProvider.html).
- [getUid](https://developer.android.com/reference/android/view/inputmethod/InputBinding.html#getUid())is guaranteed to not be spoofed, which can later be compared with[getCallingUid](https://developer.android.com/reference/android/os/Binder.html#getCallingUid())in the[ContentProvider](https://developer.android.com/reference/android/content/ContentProvider.html).  

## Public constructors

### InputConnectionCompat

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
[InputConnectionCompat](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#InputConnectionCompat())()
```
| **This function is deprecated.**   
|
This type should not be instantiated as it contains only static methods.  

## Public functions

### commitContent

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)                        | [InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)with which commitContent API will be called                                           |
| `editorInfo: `[EditorInfo](https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html)                                       | [EditorInfo](https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html)associated with the given`inputConnection`                                                      |
| `inputContentInfo: `[InputContentInfoCompat](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputContentInfoCompat) | content information to be passed to the editor                                                                                                                                                |
| `flags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                               | `0`or[INPUT_CONTENT_GRANT_READ_URI_PERMISSION](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#INPUT_CONTENT_GRANT_READ_URI_PERMISSION()) |
| `opts: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`?`                                                                | optional bundle data. This can be`null`                                                                                                                                                       |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `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](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)  

```
java-static fun [createWrapper](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#createWrapper(android.view.inputmethod.InputConnection,android.view.inputmethod.EditorInfo,androidx.core.view.inputmethod.InputConnectionCompat.OnCommitContentListener))(
    inputConnection: InputConnection,
    editorInfo: EditorInfo,
    onCommitContentListener: InputConnectionCompat.OnCommitContentListener
): InputConnection
```
| **This function is deprecated.**   
|
| Use[and { } instead.](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#createWrapper(android.view.View,android.view.inputmethod.InputConnection,android.view.inputmethod.EditorInfo))

Creates a wrapper[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)object from an existing[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)and[OnCommitContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat.OnCommitContentListener)that can be returned to the system.

By returning the wrapper object to the IME, the editor can be notified by[onCommitContent](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat.OnCommitContentListener#onCommitContent(androidx.core.view.inputmethod.InputContentInfoCompat,int,android.os.Bundle))when the IME calls[commitContent](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat#commitContent(android.view.inputmethod.InputConnection,android.view.inputmethod.EditorInfo,androidx.core.view.inputmethod.InputContentInfoCompat,int,android.os.Bundle))and the corresponding Framework API that is available on API \>= 25.  

|                                                                                               Parameters                                                                                                |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
| `inputConnection: `[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)                                                                             | [InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)to be wrapped                    |
| `editorInfo: `[EditorInfo](https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html)                                                                                            | [EditorInfo](https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html)associated with the given`inputConnection` |
| `onCommitContentListener: `[InputConnectionCompat.OnCommitContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/inputmethod/InputConnectionCompat.OnCommitContentListener) | the listener that the wrapper object will call                                                                                           |

|                                                 Returns                                                  |
|----------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| [InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html) | a wrapper[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)object that can be returned to the IME |

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | when`inputConnection`,`editorInfo`, or`onCommitContentListener`is`null` |

### createWrapper

Added in[1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)  

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

Creates a wrapper[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)that implements`InputConnection`'s features on past versions of Android.

Currently, handles[commitContent](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html#commitContent(android.view.inputmethod.InputContentInfo, int, android.os.Bundle))by dispatching to[performReceiveContent](https://developer.android.com/reference/kotlin/androidx/core/view/ViewCompat#performReceiveContent(android.view.View,androidx.core.view.ContentInfoCompat)), enabling apps to use[setOnReceiveContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/ViewCompat#setOnReceiveContentListener(android.view.View,java.lang.String[],androidx.core.view.OnReceiveContentListener))to specify handling for content insertion from the IME.

Usage:  

```kotlin
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](https://developer.android.com/reference/android/view/View.html)                                              | The view that the given input connection is associated with.    |
| `inputConnection: `[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html) | The input connection to be wrapped.                             |
| `editorInfo: `[EditorInfo](https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html)                | The editor metadata associated with the given input connection. |

|                                                 Returns                                                  |
|----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| [InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html) | A wrapper[InputConnection](https://developer.android.com/reference/android/view/inputmethod/InputConnection.html)object that can be returned to the IME. |