Android的Facebook的意图 [英] Android Facebook Intent

查看:154
本文介绍了Android的Facebook的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这个code张贴在Facebook,但它并没有与官方的Facebook应用程序的工作,因为它试图发送一个链接。有没有解决这个办法吗?

 意图S =新意图(android.content.Intent.ACTION_SEND);

s.setType(text / plain的);
s.putExtra(Intent.EXTRA_SUBJECT,报价);
s.putExtra(Intent.EXTRA_TEXT,qoute);

startActivity(Intent.createChooser(S,报价));
 

解决方案

这是在官方的Facebook应用程序中的错误。我不得不code我自己的活动来做到这一点使用Facebook SDK为Android。请参见下面的code样本。

 公共类FacebookActivity扩展活动实现DialogListener
{

    私人facebook facebookClient;
    私人的LinearLayout facebookButton;
    私人最终字符串APP_API_ID =XXXXXXXX;


    @覆盖
    保护无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        facebookClient =新的Facebook();
        //替换为您自己APP_API_ID
        facebookClient.authorize(这一点,APP_API_ID,
            新的String [] {publish_stream,read_stream,offline_access},这一点);


    }

    @覆盖
    公共无效的onComplete(束值)
    {

        如果(values​​.isEmpty())
        {
            //跳过点击?

        }

        //如果facebookClient.authorize(...)是成功的,这种运行
        //成功后在此之后也跑
        //张贴后,的post_id被加到值束
        //我使用从电话之间的区别
        // faceBook.authorize(...),并从成功后打电话
        //是否有这样做的更好的办法?
        如果(!values​​.containsKey(的post_id))
        {
            尝试
            {
                捆绑参数=新包();
                parameters.putString(信息,你的文本份额去HERE); //张贴到墙上的消息
                facebookClient.dialog(这一点,stream.publish,参数,这一点); //stream.publish是一个API调用


            }
            赶上(例外五)
            {
                // TODO:处理异常
                的System.out.println(e.getMessage());
            }

        }

    }

    @覆盖
    公共无效onerror的(DialogError E)
    {
        返回;
    }

    @覆盖
    公共无效onFacebookError(FacebookError E)
    {
        返回;
    }

    @覆盖
    公共无效OnCancel的()
    {
        返回;
    }

}
 

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"));

解决方案

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

}

这篇关于Android的Facebook的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆