Android: Delete single item from clipboard programmatically

守給你的承諾、 提交于 2019-12-11 16:33:58

问题


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.



来源:https://stackoverflow.com/questions/51548380/android-delete-single-item-from-clipboard-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!