1

I am trying to implement image keyboard support in my app. I followed official documentation. To support this I needed to override EditText's onCreateInputConnection to tell softkeyboard what app is supporting & a callback to get the selected content Uri.

EditText :

override fun onCreateInputConnection(editorInfo: EditorInfo): InputConnection {
    val ic: InputConnection = super.onCreateInputConnection(editorInfo)
    EditorInfoCompat.setContentMimeTypes(editorInfo, arrayOf("image/jpeg", "image/png"))

    val callback =
        InputConnectionCompat.OnCommitContentListener { inputContentInfo, flags, opts ->
            val lacksPermission = (flags and
                    InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0
            // read and display inputContentInfo asynchronously
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && lacksPermission) {
                try {
                    inputContentInfo.requestPermission()
                } catch (e: Exception) {
                    return@OnCommitContentListener false // return false if failed
                }
            }

            // read and display inputContentInfo asynchronously.
            // call inputContentInfo.releasePermission() as needed.

            true  // return true if succeeded
        }
    return InputConnectionCompat.createWrapper(ic, editorInfo, callback)
}

its working fine. Surprise!!!

problem is when I added intent filter to a activity. After adding intent filter callback InputConnectionCompat.OnCommitContentListener doesn't called anymore & it opens activity with supported intent filter.

Manifest :

<activity
            android:name=".Main2Activity"
            android:label="@string/title_activity_main2">

        <intent-filter> <-- this filter is added
            <action android:name="android.intent.action.SEND"/>

            <category android:name="android.intent.category.DEFAULT"/>

            <data android:mimeType="image/*"/>
        </intent-filter>
    </activity>

sample is available in github Thanks in advance.

Sayem
  • 4,891
  • 3
  • 28
  • 43

1 Answers1

1

Not sure why & how, but changing from

EditorInfoCompat.setContentMimeTypes(editorInfo, arrayOf("image/jpeg", "image/png"))

to

EditorInfoCompat.setContentMimeTypes(editorInfo, arrayOf("image/*"))

solved the problem

Sayem
  • 4,891
  • 3
  • 28
  • 43
  • It was passing the wrong mime type for the editorInfo. It was set to be jpeg or png while the selected images where gifs/stickers. Now any kind of image can be selected. – Ricardo A. Jun 11 '19 at 17:42