Skip to content

Instantly share code, notes, and snippets.

@matthewmorrone
Created November 2, 2020 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmorrone/d82a4ea0dc078a959a58b6abc2ae1752 to your computer and use it in GitHub Desktop.
Save matthewmorrone/d82a4ea0dc078a959a58b6abc2ae1752 to your computer and use it in GitHub Desktop.
EditText editText = new EditText(this) {
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
final InputConnection ic = super.onCreateInputConnection(editorInfo);
EditorInfoCompat.setContentMimeTypes(editorInfo,
new String [] {"image/png"});
final InputConnectionCompat.OnCommitContentListener callback =
new InputConnectionCompat.OnCommitContentListener() {
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo,
int flags, Bundle opts) {
// read and display inputContentInfo asynchronously
if (BuildCompat.isAtLeastNMR1() && (flags &
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
}
catch (Exception e) {
return false; // return false if failed
}
}
// read and display inputContentInfo asynchronously.
// call inputContentInfo.releasePermission() as needed.
return true; // return true if succeeded
}
};
return InputConnectionCompat.createWrapper(ic, editorInfo, callback);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment