Clear Clipboard on SGS2 (api 10)
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.s开发者_StackOverflowetText("");
It didn't work. Ideas?
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
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.
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("");
}
}
});
精彩评论