The Android Clipboard-Service allows you just to add text or other items into the clipboard, where on most Android devices the Clipdata items will be inserted into a stack with undefined max number of content. My problem is the following: I have a password manager app which can insert a chosen password into the clipboard but because passwords are highly sensitive data I would like to remove an inserted password after the defined timeout has passed. So my question is the following: Is it somehow possible to get an advanced access to the Clipboard entries and modify it somehow? I know that the framework itself does not allow that but is there a hacky way to do it?
-
Please do not post that I can insert empty text into the clipboard till all items are overwritten, this does not work on my smartphone, when I try to add multiple empty strings as clipdata the first will be added all other not. By the way if it would work on some devices this is a messy way to do that because I don´t care about the other items in the clipboard I just want to remove the passwords inserted from my app – Idi Amin Dada Jul 26 '18 at 22:39
1 Answers
the Clipdata items will be inserted into a stack with undefined max number of content
The "stack" is of size 1. There is one system clipboard entry per user. See, for example, the Android 8.1 system service that implements the clipboard. Each PerUserClipboard
holds a single ClipData
, not a stack.
It is possible that third-party apps offer some sort of clipboard extender, and it is possible that device manufacturers or custom ROM developers might modify how Android handles the clipboard. However, those go beyond the scope of the OS itself.
Is it somehow possible to get an advanced access to the Clipboard entries and modify it somehow?
You would need to ask the developer of whatever is offering this extended clipboard capability. Perhaps they have an API that you can use.
You can set the current clipboard entry using ClipboardManager
; on Android 9.0+, you can clear the current clipboard entry using ClipboardManager
as well. Both will affect the current user... but only for the single-entry system clipboard.

- 986,068
- 189
- 2,389
- 2,491
-
I know that the Clipboard just contains one ClipData item, but this ClipData item contains multiple entries witch are LIFO-sorted so I called it stack. BTW I also mean the ClipData items with Clipboard entries, sorry for the confusing expression here... – Idi Amin Dada Jul 27 '18 at 18:01
-
@IdiAminDada: OK, then, if you are really asking if you can delete one `ClipData.Item` out of the `ClipData`, that is not directly possible, as `ClipData` and `ClipData.Item` do not offer an API for modification. You could, however, retrieve the `ClipData`, try to confirm that it is yours, then build a new `ClipData` with all of the items from the old one except the one(s) that you are trying to remove. Then, put the revised `ClipData` on the clipboard. – CommonsWare Jul 27 '18 at 21:05