Android: Delete single item from clipboard program

2019-08-29 10:13发布

问题:

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?

回答1:

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.