Search code examples
androidclipboarddataclipboardmanager

Clearing Clipboard Data in Android


I'm trying to clear the Clipboard data in android as follow but its not clearing it.

ClipboardManager clipman = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipman.setPrimaryClip(null);

Any ideas ?


Solution

  • Since API 11 ClipboardManager (as old ClipboardManager class is deprecated.)

    ClipboardManager clipBoard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    ClipData data = ClipData.newPlainText("", "");
    clipBoard.setPrimaryClip(data);