Skip to content

Instantly share code, notes, and snippets.

@hitherejoe
Created August 13, 2018 13:25
Show Gist options
  • Save hitherejoe/b6b759bbbde9f6c41e7f16a1727a1a4a to your computer and use it in GitHub Desktop.
Save hitherejoe/b6b759bbbde9f6c41e7f16a1727a1a4a to your computer and use it in GitHub Desktop.
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)
}
@luck-alex13
Copy link

Hi! What is a mediaSelectionListener? Is that your custom interface?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment