Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook Intent

I'm using this code to post on Facebook, but it does not work with the official Facebook app because it tries to send as a link. Is there any way around this?

Intent s = new Intent(android.content.Intent.ACTION_SEND);

s.setType("text/plain");
s.putExtra(Intent.EXTRA_SUBJECT, "Quote");
s.putExtra(Intent.EXTRA_TEXT, qoute);

startActivity(Intent.createChooser(s, "Quote"));
like image 931
zaid Avatar asked Aug 13 '10 22:08

zaid


People also ask

How can I open Facebook programmatically in android?

To opening facebook app on specified profile page, you can do this: String facebookId = "fb://page/<Facebook Page ID>"; startActivity(new Intent(Intent. ACTION_VIEW, Uri.

What does intent mean in android?

An Intent is a messaging object you can use to request an action from another app component. Although intents facilitate communication between components in several ways, there are three fundamental use cases: Starting an activity. An Activity represents a single screen in an app.


1 Answers

It's a bug in the official facebook app. I had to code my own activity to do it using the Facebook SDK for Android. See the code sample below.

public class FacebookActivity extends Activity implements DialogListener
{

    private Facebook facebookClient;
    private LinearLayout facebookButton;
    private final String APP_API_ID = "XXXXXXXX";


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        facebookClient = new Facebook();
        // replace APP_API_ID with your own
        facebookClient.authorize(this, APP_API_ID,
            new String[] {"publish_stream", "read_stream", "offline_access"}, this);


    }

    @Override
    public void onComplete(Bundle values)
    {

        if (values.isEmpty())
        {
            //"skip" clicked ?

        }

        // if facebookClient.authorize(...) was successful, this runs
        // this also runs after successful post
        // after posting, "post_id" is added to the values bundle
        // I use that to differentiate between a call from
        // faceBook.authorize(...) and a call from a successful post
        // is there a better way of doing this?
        if (!values.containsKey("post_id"))
        {
            try
            {
                Bundle parameters = new Bundle();
                parameters.putString("message", "YOUR TEXT TO SHARE GOES HERE");// the message to post to the wall
                facebookClient.dialog(this, "stream.publish", parameters, this);// "stream.publish" is an API call


            }
            catch (Exception e)
            {
                // TODO: handle exception
                System.out.println(e.getMessage());
            }

        }

    }

    @Override
    public void onError(DialogError e)
    {       
        return;
    }

    @Override
    public void onFacebookError(FacebookError e)
    {   
        return;
    }

    @Override
    public void onCancel()
    {      
        return;     
    }

}
like image 147
PinouinFictif Avatar answered Oct 20 '22 06:10

PinouinFictif