Clear Clipboard on SGS2 (api 10)

浪尽此生 提交于 2019-12-07 03:54:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!