5

None of the methods I found worked.

Here is what I tried :

1/ Using clearPrimaryClip() method of ClipboardManager class

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

This doesn't do anything. The clipboard still holds my old item.

2/ Using the suggestions from stackoverflow

ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", " ");
clipboard.setPrimaryClip(clip);

This one only adds an empty clipboard item to the list of items. The old clipboard item is not cleared or removed.

Is there a programmatic way to delete an item from the clipboard item list?

Thanks.

  • Did you ever figure this out? – user167698 Jun 18 '19 at 21:24
  • 1
    @user167698 There is no way to do this programmatically, at least for Android versions which support multiple clips in the clipboard (starting Android 4.4.2 ?). With older versions, which couldn't contain more than 1 clip in the clipboard, setting the data of the clip to " " did the trick, but this does not work anymore. Cheers – El Mostafa IDRASSI Jun 19 '19 at 17:02
  • 1
    Kaspersky Password App can do that, so it is possible. But I'm not sure how. – Leonardo Sibela Mar 13 '23 at 21:25
  • @ElMostafaIDRASSI does this question have the answer you were looking for? https://stackoverflow.com/a/28353981/3590155 – Leonardo Sibela Mar 13 '23 at 21:33
  • If you found out how to achieve that, I'm insterested too. – matteoh Mar 16 '23 at 10:24

1 Answers1

1

You can simply send multiple empty values to the clipboar:

(requireActivity().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager).apply {
    for (i in 1..50) {
        setPrimaryClip(ClipData.newPlainText(null, ""))
    }
}
Leonardo Sibela
  • 1,613
  • 1
  • 18
  • 39