Skip to content

Instantly share code, notes, and snippets.

@hitherejoe hitherejoe/image_support.kt Secret
Created Aug 13, 2018

Embed
What would you like to do?
override fun onCreateInputConnection(editorInfo: EditorInfo): InputConnection {
val inputConnection = super.onCreateInputConnection(editorInfo)
EditorInfoCompat.setContentMimeTypes(editorInfo, arrayOf("image/gif", "image/png"))
val callback = InputConnectionCompat.OnCommitContentListener { inputContentInfo, flags, _ ->
if (ApiLevelHelper.isAtLeast(25) && flags and InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION != 0) {
try {
inputContentInfo.requestPermission()
} catch (e: Exception) {
return@OnCommitContentListener false
}
mediaSelectionListener?.onMediaSelected(inputContentInfo.contentUri)
}
true
}
return InputConnectionCompat.createWrapper(inputConnection, editorInfo, callback)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.