Skip to content

Commit

Permalink
fix(android) : App can crash on clipboard.read if empty (#2815)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdnp authored Apr 29, 2020
1 parent 3638a89 commit fc33265
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,28 @@ public void read(PluginCall call) {
ClipboardManager clipboard = (ClipboardManager)
c.getSystemService(Context.CLIPBOARD_SERVICE);

CharSequence value = "";
if(clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
Log.d(getLogTag(), "Got plaintxt");
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
value = item.getText();
} else {
Log.d(getLogTag(), "Not plaintext!");
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
value = item.coerceToText(this.getContext()).toString();
CharSequence value = null;

if (clipboard.hasPrimaryClip()) {
if(clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
Log.d(getLogTag(), "Got plaintxt");
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
value = item.getText();
} else {
Log.d(getLogTag(), "Not plaintext!");
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
value = item.coerceToText(this.getContext()).toString();
}
}

JSObject ret = new JSObject();
String type = "text/plain";
ret.put("value", value != null ? value : "");
if (value != null && value.toString().startsWith("data:")) {
type = value.toString().split(";")[0].split(":")[1];
}
ret.put("type", type);

call.success(ret);
}
}

0 comments on commit fc33265

Please sign in to comment.