ShareActionProvider 不会与 Facebook 共享 Intent 中的文本



我正在使用ShareActionProvider(android.widget.ShareActionProvider)来共享简单的文本。它适用于Gmail、WhatsApp等,但不适用于Facebook。。。

它不共享意向书附带的文本,而是要求用户写一篇新的帖子。

如何解决这个问题?

这是我的代码:

XML:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
>
<item android:id="@+id/action_share"
    android:title="@string/action_share"
    android:showAsAction="always"
    android:actionProviderClass="android.widget.ShareActionProvider" />
</menu>

Java:

@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // Inflate the menu; this adds items to the action bar if it is present.
        inflater.inflate(R.menu.detailfragment, menu);
        // Retrieve the share menu item
        MenuItem share = menu.findItem(R.id.action_share);
        // Get the provider and hold onto it to set/change the share intent.
        mShareActionProvider = (ShareActionProvider) share.getActionProvider();
        // Attach an intent to this ShareActionProvider.  You can update this at any time,
        // like when the user selects a new piece of data they might like to share.
        if (mShareActionProvider != null && mForecastStr != null ) {
            mShareActionProvider.setShareIntent(createShareIntent());
            Log.v(LOG_TAG, "mForecast: " + mForecastStr);
            Log.v(LOG_TAG, "Intent: " + mShareActionProvider);
        } else {
            Log.d(LOG_TAG, "Share Action Provider is null?");
        }
    }

    public Intent createShareIntent() {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, mForecastStr);
        return shareIntent;
    }

谢谢!!

很遗憾,您无法解决它。Facebook不处理EXTRA_TEXT字段。您可以查看此错误报告页面。

有一个中间的解决方案。FB确实不共享TEXTS。他们说这是对用户言论自由的攻击。但是,你有一个解决方案。你可以传递一个链接。然后FB将"意向"转换为图像和链接,并添加到未来的响应中。但它留下了空白的用户写作空间。。。例如尝试:

shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");

最新更新