如何添加剪贴板选项ACTION_SEND意图(how to add clipboard option

2019-10-29 14:39发布

不知怎的,我已经看到了可以添加剪贴板选项共享选项的应用程序。

像这样的东西截图

我怎样才能做到这一点?

我试图增加额外的意图,但额外的意图并未现身

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

Answer 1:

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);


文章来源: how to add clipboard option to action_send intent