从剪贴板管理Android的复制/粘贴剪贴板、Android

由网友(爱就疯狂不爱就坚强)分享简介:是否有可能使其粘贴文本目前主要集中编辑短信发送过去的命令。场景:Is it possible to send past command so that it pastes text into currently focused edit text.Scenario:后台服务侦听通知(完成)当收到通知文本需要被复制...

是否有可能使其粘贴文本目前主要集中编辑短信发送过去的命令。场景:

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

阅读全文

相关推荐

最新文章