Commit a146ef59 authored by 汪林玲's avatar 汪林玲

清空粘贴板

parent 6ada195c
......@@ -4,6 +4,7 @@ import android.content.ClipData;
import android.content.ClipDescription;
import android.content.ClipboardManager;
import android.content.Context;
import android.text.TextUtils;
public class Handler {
private Context context;
......@@ -18,7 +19,6 @@ public class Handler {
if (data == null) {
return "";
}
if ((c.getPrimaryClipDescription() != null && c.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) || data.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
String str = data.getItemAt(0).getText().toString();
return str;
......@@ -28,14 +28,19 @@ public class Handler {
}
public void setText(String text) {
if (text == null) {
text = "";
}
ClipboardManager c = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText(null, text);
c.setPrimaryClip(clipData);
clipboard.setPrimaryClip(clipData);
try {
if(TextUtils.isEmpty(text)){
clipboard.clearPrimaryClip();
}
}catch (Exception e){
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment