我试图在通过 ActionBarSherlock 使用共享操作提供程序时共享纯文本,但只有四个选项可以共享,没有“查看全部...”选项。
这是为什么?
这是它的样子:
这就是我想要的样子:
最佳答案
好吧,不管 ActionBarSherlock 是否首先测试以查看您是否正确创建了您的 Intent ,ABS 使用与通用选择器相同的代码,以便在您执行此代码时查看您正在寻找的应用程序是否出现。
Intent I= new Intent(Intent.ACTION_SEND);
I.setType("text/plain");
I.putExtra(android.content.Intent.EXTRA_TEXT, "My Test Text");
startActivity(Intent.createChooser(I,"Share using ..."));
所有处理纯文本的应用程序都会显示,如果 facebook 或您期望的任何内容不存在,则这些应用程序不支持您注册的类型(纯文本/文本)的 ACTION_SEND Intent 。 (Facebook 有,但稍后会详细介绍)
ABS 有一个使用共享操作提供程序的示例,但它尝试发送照片,而不是文本消息(状态更新),您应该使用的设置是这样的
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate your menu.
getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);
// Set file with share history to the provider and set the share intent.
MenuItem item = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
ShareActionProvider provider = (ShareActionProvider) item.getActionProvider();
provider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
// Note that you can set/change the intent any time,
// say when the user has selected an image.
provider.setShareIntent(createShareIntent());
return true
}
这是将用于匹配应用程序并将其从示例中列出的 Intent
private Intent createShareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/plain");
Uri uri = Uri.fromFile(getFileStreamPath("shared.png"));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TITLE, "This is an android icon");
return shareIntent;
}
但你希望它是
private Intent createShareIntent() {
Intent I= new Intent(Intent.ACTION_SEND);
I.setType("text/plain");
I.putExtra(android.content.Intent.EXTRA_SUBJECT, "TEST - Disregard");
I.putExtra(android.content.Intent.EXTRA_TEXT, Uri.parse("http://noplace.com"));
}
这应该会在 ABS 中为您提供与我在上面的选择器中展示的小测试 stub 中相同的列表。
现在是坏消息。 Facebook 应用程序并没有真正起作用,它会调出用户更新页面,但不会填写文本。这是一个又开又关的破损,但我昨晚试过了,但失败了。这是 Facebook 应用程序的一个已报告并已接受的错误。虽然无法设置标题,但您可以发布照片,请参阅 How many times will Facebook break/fix this?
关于android - 带有 ActionBarSherlock 的 ShareActionProvider 只有四个选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10887929/