Android facebook发送消息 [英] Android facebook send a message

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

问题描述

我必须通过Android应用程序向Facebook的朋友发送消息。我已经完成了所有功能,并尝试了一个代码来发送消息给Facebook的朋友。但是显示一个错误,对话框不可用于此设备

I have to send a message to a facebook friend via an android app.I have done all functions and tried a code to send message to facebook friend.But it showing an error that the dialog is not available for this device.

以下是我向Facebook的朋友发送消息的代码:

Here is my code to send a message to facebook friend:

Facebook facebook = new Facebook(APP_ID);
        Bundle params = new Bundle();
        params.putString("to", Constant.facebookIdBuffer.toString());
        params.putString("name", "Goal Machine");//title
        params.putString("link", Constant.shortAppUrlForAndroid+"\n"+Constant.shortAppUrlForIphone);//message
        facebook.dialog(_activity, "send", params, new DialogListener() {//apprequests
            @Override
            public void onComplete(Bundle values) {
                Constant.facebookIdBuffer=null;
                //postToWall("@"+Constant.facebookIdBuffer.toString()+sendInvite);
            }

            @Override
            public void onFacebookError(FacebookError error) {
                Constant.showAlertDialog("Error", "Can't send ally request!", _activity.getParent(), false);
                Constant.facebookIdBuffer=null;
            }

            @Override
            public void onError(DialogError e) {
                Constant.showAlertDialog("Error", "Can't send ally request!", _activity.getParent(), false);
                Constant.facebookIdBuffer=null;
            }

以下是显示错误的屏幕短信:

Here is the screen short showing error:

请给我一个发送消息的方式来发送一个链接到Facebook的朋友。

Please suggest me a way to send a message with links to facebook friend.

推荐答案

你可以使用MessengerUtils从最新的Facebook Android sdk发送带有附件的消息。

You can use MessengerUtils from Latest facebook Android sdk to send the message with attachments.

您可以使用以下MIME类型发送附件:

You can send attachment with following mime types:

发送图像的示例代码如下

Sample code to send image is like below

String mimeType = "image/jpeg";

// contentUri points to the content being shared to Messenger
ShareToMessengerParams shareToMessengerParams =
        ShareToMessengerParams.newBuilder(contentUri, mimeType)
                .build();

// Sharing from an Activity
MessengerUtils.shareToMessenger(
       this,
       REQUEST_CODE_SHARE_TO_MESSENGER,
       shareToMessengerParams);

更多文档位于 https://developers.facebook.com/docs/ messenger / android

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

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