how to add clipboard option to action_send intent

大憨熊 提交于 2019-12-12 00:11:49

问题


Somehow I've seen an application that can add Clipboard option to share options.

Something like this screenshot

How can I do that?

I tried to add extra intent, but the additional intent didn't show up

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

Thank you :D


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


来源:https://stackoverflow.com/questions/16416918/how-to-add-clipboard-option-to-action-send-intent

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