user3594510
user3594510

Reputation: 57

Clear ALL clipboard entries

On my Samsung Tab 3 running Android 4.1.2 multiple copies to clipboard produce a clipboard containing each copy. This is seen through a button on the tight bottom of the slide-up keyboard.

I'd like to delete all these copies programmatically, however, the ClipboardManager doesn't appear to offer methods to do this. How can delete everything that has been copied to the clipboard?

Thanks,

Chris

Upvotes: 8

Views: 13240

Answers (5)

Mergu.
Mergu.

Reputation: 151

ClipboardManager clipService = (ClipboardManager)activity.getSystemService(Context.CLIPBOARD_SERVICE);`<br>
`ClipData clipData = ClipData.newPlainText("", "");`
<br>
`clipService.setPrimaryClip(clipData);

Upvotes: 15

barnabas
barnabas

Reputation: 139

To actually delete the entries (instead of exchanging them with an empty string via setPrimaryClip()), with API level 28+:

ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
while (clipboardManager.hasPrimaryClip()) {
    clipboardManager.clearPrimaryClip()
}

Upvotes: 0

Matt
Matt

Reputation: 459

From API 28

ClipboardManager mCbm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
mCbm.clearPrimaryClip()

Upvotes: 4

Chris Thornton
Chris Thornton

Reputation: 15817

I don't think you can. It sounds like Samsung has written a clipboard extender that monitors clipboard events and retains a copy of everything.

There is no way to access the history without (the user) interacting with the history list via the UI.

One possible work-around: If the history list is of the limited/recycling variety (i.e. limited to 10 with new items overwriting old items), then you may be able to effectively erase it by repeatedly sending blank strings (or harmless non-duplicate strings such as 'empty1', 'empty2', etc..) Whatever you do, you'll end up overwriting something that the user has deemed to be important, and THE USER WILL HATE YOU.

Upvotes: 4

GoRoS
GoRoS

Reputation: 5375

Using the manager you mentioned, you can set an empty string to it with setText to clear the clipboard.

ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
mClipboardManager.setText("");

Upvotes: 0

Related Questions