Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ public ClipboardData read() {
if (clipboard != null) {
CharSequence value = null;

if (clipboard.hasPrimaryClip()) {
if (clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
// hasPrimaryClip() can be true while getPrimaryClip() and
// getPrimaryClipDescription() still return null, e.g. while the app
// is not focused yet, so read the clip once and check it.
ClipData clip = clipboard.getPrimaryClip();
if (clip != null && clip.getItemCount() > 0) {
ClipDescription description = clip.getDescription();
ClipData.Item item = clip.getItemAt(0);
if (description != null && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
Logger.debug(TAG, "Got plaintxt");
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
value = item.getText();
} else {
Logger.debug(TAG, "Not plaintext!");
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
value = item.coerceToText(context).toString();
value = item.coerceToText(context);
}
}

Expand Down