ActionBarSherlock下ShareActionProvider仅有四个选项

7
我正在尝试使用ActionBarSherlock的Share Action Provider共享纯文本,但只有四个共享选项,没有“查看全部...”选项。
为什么会这样呢?
这是它的样子:
而我希望它看起来像这样:

ActionShareProvider列出了可以处理提供程序所创建的意图类型的所有应用程序。如果您只看到4个,则这些是仅接受所创建的意图类型数据的特定应用程序。此外,为什么您希望在纯文本中列出照片共享(类别或应用程序,不确定)呢? - Idistic
我正在尝试使用共享操作提供程序作为用户分享下载我的应用程序的链接的选项,但像Facebook和Twitter这样的应用程序没有选项。我想要的外观图片是我已经下载的另一个应用程序,当我选择“查看全部...”时,有大约10个不同的应用程序可以分享。 - GreekOphion
2个回答

8

好的,无论是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"));
    }

这应该与我在上面的选择器示例中显示的ABS列表相同。
现在是坏消息。Facebook应用程序实际上不起作用,它会打开用户更新页面,但不会填写文本。这是一个时断时续的故障,但我昨晚尝试了一下,它失败了。这是Facebook应用程序的一个已知问题和被接受的错误报告。您可以发布照片,但不能设置标题,请参见Facebook还会出多少次错?

3

未来读者请注意,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>

这篇文章是关于信息的 - 我花了很长时间才找到答案,所以我想让未来的读者更容易找到。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接