@@ -48,23 +48,28 @@ public void read(PluginCall call) {
48
48
ClipboardManager clipboard = (ClipboardManager )
49
49
c .getSystemService (Context .CLIPBOARD_SERVICE );
50
50
51
- CharSequence value = "" ;
52
- if (clipboard .getPrimaryClipDescription ().hasMimeType (ClipDescription .MIMETYPE_TEXT_PLAIN )) {
53
- Log .d (getLogTag (), "Got plaintxt" );
54
- ClipData .Item item = clipboard .getPrimaryClip ().getItemAt (0 );
55
- value = item .getText ();
56
- } else {
57
- Log .d (getLogTag (), "Not plaintext!" );
58
- ClipData .Item item = clipboard .getPrimaryClip ().getItemAt (0 );
59
- value = item .coerceToText (this .getContext ()).toString ();
51
+ CharSequence value = null ;
52
+
53
+ if (clipboard .hasPrimaryClip ()) {
54
+ if (clipboard .getPrimaryClipDescription ().hasMimeType (ClipDescription .MIMETYPE_TEXT_PLAIN )) {
55
+ Log .d (getLogTag (), "Got plaintxt" );
56
+ ClipData .Item item = clipboard .getPrimaryClip ().getItemAt (0 );
57
+ value = item .getText ();
58
+ } else {
59
+ Log .d (getLogTag (), "Not plaintext!" );
60
+ ClipData .Item item = clipboard .getPrimaryClip ().getItemAt (0 );
61
+ value = item .coerceToText (this .getContext ()).toString ();
62
+ }
60
63
}
64
+
61
65
JSObject ret = new JSObject ();
62
66
String type = "text/plain" ;
63
67
ret .put ("value" , value != null ? value : "" );
64
68
if (value != null && value .toString ().startsWith ("data:" )) {
65
69
type = value .toString ().split (";" )[0 ].split (":" )[1 ];
66
70
}
67
71
ret .put ("type" , type );
72
+
68
73
call .success (ret );
69
74
}
70
75
}
0 commit comments