【问题标题】:Only Four Options For ShareActionProvider With ActionBarSherlock使用 ActionBarSherlock 的 ShareActionProvider 只有四个选项
【发布时间】:2012-06-04 20:30:34
【问题描述】:

我正在尝试通过 ActionBarSherlock 使用共享操作提供程序来共享纯文本,并且只有四个选项可以共享它,并且没有“查看全部...”选项。

这是为什么呢?

这就是它的样子:

这就是我想要的样子:

【问题讨论】:

  • ActionShareProvider 列出了所有可以处理您为提供者创建的意图类型的应用。如果您只看到 4 个,那么这些是唯一接受您创建的意图类型数据的特定应用程序。另外,您为什么希望以纯文本形式列出照片共享(类别或应用,不确定)?
  • 我正在尝试使用 Share Action Provider 作为用户共享链接以下载我的应用程序的选项,我有 facebook 和 twitter 等应用程序,这些应用程序没有选项。我想要的图片是我下载的另一个应用程序,当我选择“查看全部...”时,我可以共享大约 10 个不同的应用程序。

标签: android android-actionbar actionbarsherlock shareactionprovider


【解决方案1】:

好的,所以不管 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?

【讨论】:

    【解决方案2】:

    请注意,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>
    

    这个信息答案 - 我花了很长时间才找到它,所以我想让未来的读者更容易找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多