5

I am trying to implement sharing a simple string inside my application. Obviously everything other than Facebook works. As far as I know, now I have to use their Facebook SDK to post statuses on a wall.

However, if I do implement it using their SDK, is there a way to have it incorporated into the chooser (default or ShareActionProvider) and somehow override it and insert the Facebook SDK's implementation?

Or do I have to create a dedicated button?

//EDIT

package com.example.shareactionproviderdemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Test message");
        startActivity(Intent.createChooser(sharingIntent, "Share using"));
    }

}

enter image description here

Peter O.
  • 32,158
  • 14
  • 82
  • 96
urSus
  • 12,492
  • 12
  • 69
  • 89

1 Answers1

4

The answer is you cannot share a string to the user's own wall by using intents. You need the SDK in order to do that. The reason why is because Facebook does not allow the prefilling of the user's status update as seen in Platform Policy IV.2.

However, if you use the SDK, we have provided a feed dialog that prompts the user to share a status and it allows parts of the status update to be prefilled by the developer. It is not incorporated into the Android's native chooser, however.

The external bug report that tracked this issue is here.

Jesse Chen
  • 4,928
  • 1
  • 20
  • 20
  • 1
    This does not work for me, when the chooser pops up, I choose Facebook and all I see is an empty edittext, as if the EXTRA_TEXT string wasnt received. Any idea what am I doing wrong? I see youre forking at facebook. //I updated the question with snippet and a screenshot – urSus Nov 14 '12 at 13:08
  • can you try using `EXTRA_SUBJECT` instead of `EXTRA_TEXT` and report back if it works for you? – Jesse Chen Nov 15 '12 at 01:31
  • This doesnt work either, does it work for you? Because it has never worked for me in the past and Ive found numerous threads about this issue (http://stackoverflow.com/questions/3515198/share-text-on-facebook-from-android-app-via-action-send). P.S. sharing a URL works, exactly as posted in the thread. – urSus Nov 15 '12 at 14:44
  • Yes, this is the source code in my Android app and it works fine with Facebook and etc. – Jesse Chen Nov 15 '12 at 19:30
  • what android version are you on? – urSus Nov 15 '12 at 20:00
  • works for all my devices that has the facebook app installed, from 2.3 all the way to 4.2 – Jesse Chen Nov 16 '12 at 03:41
  • well I have no clue then, btw sharing works on alternative clien applications like Friendcaster, or any other like Google+, Gmail etc...could you please send me a helloworld.apk with only that code that works for you? Starting to get hopeless. – urSus Nov 16 '12 at 13:50
  • Update your Facebook application on the device and you do not need the facebook sdk when you use intents. I remember there was a bug in the earlier facebook application which did not recognize EXTRA_TEXT. – PravinCG Nov 25 '12 at 16:29
  • Wow I completely blanked out and was not thinking and made a big mistake. Without the SDK, you cannot share a string to Facebook. I updated my answer to correctly answer your question. Let me know if you still have questions, and I apologize for the initial wrong answer. – Jesse Chen Nov 29 '12 at 05:20
  • That link to Platform Policy IV.2 is awesome... much like any other 2-3 month old link to Facebook documentation. – nikib3ro Mar 02 '13 at 01:58