Makoto
Makoto

Reputation: 1475

ShareActionProvider doesn't share text from Intent with Facebook

I'm using a ShareActionProvider(android.widget.ShareActionProvider) to share simple text. It works fine with Gmail, WhatsApp etc but not with Facebook...

It doesn't share the text attached to the Intent, instead it just ask the user to write a new post.

How to solve this?

Here is my code:

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;
    }

Thanks!!

Upvotes: 0

Views: 895

Answers (2)

yzacarias
yzacarias

Reputation: 11

There is a middle solution. It is true FB doesn't share TEXTS. They say that it is an attack to the freedom of expression of the User. But, you have a solution. You may pass a link. Then FB translate the "Intent" to a image and a link, and it added to the future response. But it leave blank the User writing space... For example try:

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

Upvotes: 1

jomartigcal
jomartigcal

Reputation: 813

Unfortunately, you can't solve it. Facebook does not handle the EXTRA_TEXT field. You can check this bug report page.

Upvotes: 1

Related Questions