问题
I'm using a Samsung Galaxy S2 and tried the following:
import android.text.ClipboardManager;
ClipboardManager clipboard = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(null);
and
clipboard.setText("");
It didn't work. Ideas?
回答1:
Their is a bug with the Samsung Galaxy. It doesn't accept setting the clipboard to a blank value. You could try setting it to a space instead.
clipboard.setText(" ");
For further information check this
回答2:
Have you tried .setPrimaryClip(ClipData clip)? The documentation reads:
public void setPrimaryClip (ClipData clip)
Since: API Level 11 Sets the current primary clip on the clipboard. This is the clip that is involved in normal cut and paste operations. Parameters
clip The clipped data item to set.
According to the docs, setText() is deprecated.
I know this question is old, but it's worth a try.
回答3:
clear clip bord for v3.0 api-11
clipboard1 = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard1
.addPrimaryClipChangedListener(new OnPrimaryClipChangedListener() {
public void onPrimaryClipChanged() {
copyText = (String) clipboard1.getText();
Log.d("Copytext", copyText);
Toast.makeText(javaButtonTest.this, copyText, Toast.LENGTH_LONG).show();
//ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (clipboard1.hasText()) {
copyText = (String) clipboard1.getText();
clipboard1.setText("");
}
}
});
来源:https://stackoverflow.com/questions/7362244/clear-clipboard-on-sgs2-api-10