好的,所以不管 ActionBarSherlock 第一次测试是否正确创建了您的意图,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 意图。 (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
}
这是用于匹配应用程序并将它们从示例中列出的意图
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 中为您提供与我在上面使用选择器显示的小测试存根中相同的列表。
现在是坏消息。 Facebook 应用程序并没有真正起作用,它会调出用户更新页面,但不会填写文本。这是一个再次打开,再次关闭的破损,但我昨晚尝试过,但失败了。这是 facebook 应用程序的一个已报告并已接受的错误。虽然无法设置标题,但您可以发布照片,请参阅How many times will Facebook break/fix this?