android intent chooser - 显示选择器,带有一个选项

时间:2017-02-07 07:56:03

标签: android android-intent android-intent-chooser

我想创建一个intent,选择只显示一个选项(复制到剪贴板),但是当我这样做时,意图会自动启动(复制到剪贴板)并且不显示选择器。 这是我的代码:

Intent copyToClipboard = new Intent(activity, ShareToClipboardActivity.class);
copyToClipboard.putExtra(Intent.EXTRA_TEXT, entry.getEntryShareLink());
LabeledIntent labeledCopyToClipboard = new LabeledIntent(copyToClipboard, activity.getPackageName(), "Copy!", 0);
List<LabeledIntent> intentList = new ArrayList<>();
intentList.add(new LabeledIntent(labeledCopyToClipboard, activity.getPackageName(), "Copy to clipboard", R.drawable.ic_content_copy_gray_24dp));

Intent chooserIntent = Intent.createChooser(new LabeledIntent(labeledCopyToClipboard, activity.getPackageName(), "Copy to clipboard", R.drawable.ic_content_copy_gray_24dp), "Share entry");
activity.startActivity(chooserIntent);

有人可以提出建议吗?

1 个答案:

答案 0 :(得分:0)

有点可疑!我是偏执狂还是你在代码的这两行中定义了嵌套意图?这有必要吗?

LabeledIntent labeledCopyToClipboard = new LabeledIntent(copyToClipboard, activity.getPackageName(), "Copy!", 0);

Intent chooserIntent = Intent.createChooser(new LabeledIntent(labeledCopyToClipboard, activity.getPackageName(), "Copy to clipboard", R.drawable.ic_content_copy_gray_24dp), "Share entry");