如何打开Facebook我发表了一些pre定义的文本和图像 [英] How to open the Facebook Write Post with some pre defined text and image

查看:117
本文介绍了如何打开Facebook我发表了一些pre定义的文本和图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我用ACTION_SEND和类型文本/纯和EXTRA_TEXT一个Intent Facebook并没有pre灌注什么。这件事情我已经看到了。每个人说,使用Facebook SDK,但我不希望我的应用程序自动发布任何东西,也从我的应用程序处理的登录令牌。我只想写后Facebook的屏幕与pre定义的文本,链接和图像打开。当我从图库应用程序共享图像就像。这可能吗?

If I use an Intent with ACTION_SEND and type "text/plain" and a EXTRA_TEXT Facebook doesn't prefill anything. That's something I've already seen. Every one says, use the Facebook SDK but I don't want my app to post anything automatically nor handle login tokens from my app. I just want the Write Post Facebook screen to be opened with a pre defined text, link and an Image. Just like when I share an image from the Gallery app. Is it possible?

推荐答案

好吧,这是不可能通过意图去做。唯一的解决办法来显示文字,图片+链接和让用户写东西之前发布是用丑陋的饲料对话框(或者创建拥有一个EditText中,用户可以编写一个成才自定义活动)。

Ok, it is impossible to do it via Intent. The only solution to show text, images + links and let the user write something before it is posted is by using the ugly Feed Dialog (or creating an custom activity with an EditText in which the user can write someting).

这里的code的作品:

Here's the code that works:

public class FacebookPostActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_facebook_post);

    Session.openActiveSession(this, false, new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if(session.isOpened()){
                publishFeedDialog();
            }
        }
    });
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

private void publishFeedDialog() {
    Bundle params = new Bundle();
    params.putString("name", "Facebook SDK for Android");
    params.putString("caption", "Build great social apps and get more installs.");
    params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
    params.putString("link", "https://developers.facebook.com/android");
    params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

    WebDialog feedDialog = new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params)
            .setOnCompleteListener(new OnCompleteListener() {
                @Override
                public void onComplete(Bundle values, FacebookException error) {
                    if(error == null){
                        final String postId = values.getString("post_id");
                        if(postId != null){
                            Toast.makeText(FacebookPostActivity.this, "Posted story, id: " + postId, Toast.LENGTH_SHORT).show();
                        }else{
                            Toast.makeText(FacebookPostActivity.this, "Publish cancelled", Toast.LENGTH_SHORT).show();
                        }
                    }else if(error instanceof FacebookOperationCanceledException){
                        // User clicked the "x" button
                        Toast.makeText(FacebookPostActivity.this, "Publish cancelled", Toast.LENGTH_SHORT).show();
                    }else{
                        // Generic, ex: network error
                        Toast.makeText(FacebookPostActivity.this, "Error posting story", Toast.LENGTH_SHORT).show();
                    }
                }
            }).build();

    feedDialog.show();
}

}

这篇关于如何打开Facebook我发表了一些pre定义的文本和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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