如何向action_send intent添加剪贴板选项

时间:2013-05-07 10:36:35

标签: android android-intent android-view

不知何故,我发现了一个可以添加剪贴板选项以共享选项的应用程序。

像这样screenshot

我该怎么做?

我尝试添加额外的意图,但附加意图没有显示

Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "Extra Text");
    intent.setType("text/plain");

    Intent clipboardIntent = new Intent();
    clipboardIntent.putExtra(Intent.EXTRA_TEXT, "Extra Text");
    clipboardIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");

    Intent chooserIntent = Intent.createChooser(intent, "Chooser Title");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { clipboardIntent });
    startActivity(chooserIntent);

谢谢:D

1 个答案:

答案 0 :(得分:0)

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
clipboard.setText("Text to copy");

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Extra Text"+clipboard.getText());
intent.setType("text/plain");



Intent chooserIntent = Intent.createChooser(intent, "Chooser Title");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { clipboardIntent });
startActivity(chooserIntent);