从剪贴板管理Android的复制/粘贴 [英] Android copy/paste from clipboard manager
本文介绍了从剪贴板管理Android的复制/粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能使其粘贴文本目前主要集中编辑短信发送过去的命令。
场景:
Is it possible to send past command so that it pastes text into currently focused edit text. Scenario:
- 后台服务侦听通知(完成)
- 当收到通知文本需要被复制到剪贴板(完成)
- 粘贴文本以任何当前重点领域,如果没有可能只需放弃粘贴命令。
我知道如何与ClipboardManager复制文本,但我不知道该怎么贴吧。
I know how to copy text with ClipboardManager, but I don't know how to paste it.
非常感谢你的帮助。
推荐答案
您可以通过粘贴文本复制及以下code ...
you can copy and paste text using following code...
//for copy
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("your_text_to_be_copied");
clipboard.setPrimaryClip(clip);
// And paste it
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
String pasteData = "";
// If it does contain data, decide if you can handle the data.
if (!(clipboard.hasPrimaryClip())) {
} else if (!(clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN))) {
// since the clipboard has data but it is not plain text
} else {
//since the clipboard contains plain text.
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
// Gets the clipboard as text.
pasteData = item.getText();
}
}
有关详细信息,请检查这里
for more details check here
这篇关于从剪贴板管理Android的复制/粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文