我正在尝试使用ActionBarSherlock的Share Action Provider共享纯文本,但只有四个共享选项,没有“查看全部...”选项。
为什么会这样呢?
这是它的样子:
而我希望它看起来像这样:
为什么会这样呢?
这是它的样子:
而我希望它看起来像这样:
好的,无论是ActionBarSherlock,首先测试一下你是否正确创建了intent,ABS使用与通用chooser相同的代码,因此执行此代码时,请查看您要查找的应用程序是否显示。
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或者你期望的其他应用程序没有显示,那么这些应用程序不支持你已注册的类型(plain/text)的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"));
}
未来读者请注意,ActionBarSherlock的ShareActionProvider
在v4.1.0版本中不支持溢出菜单。也许将来会有更新。
这是来自SampleList演示的share_action_provider.xml
文件中的代码:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_item_share_action_provider_action_bar"
android:showAsAction="always"
android:title="@string/action_bar_share_with"
android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" />
<!-- XXX: For now, ShareActionProviders must be displayed on the action bar -->
<!--item android:id="@+id/menu_item_share_action_provider_overflow"
android:showAsAction="never"
android:title="@string/action_bar_share_with"
android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" /-->
</menu>
这篇文章是关于信息的 - 我花了很长时间才找到答案,所以我想让未来的读者更容易找到。