Created
November 2, 2020 09:18
-
-
Save matthewmorrone/d82a4ea0dc078a959a58b6abc2ae1752 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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