0

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.

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:

enter image description here

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

Ricky Khatri
  • 952
  • 2
  • 16
  • 42

3 Answers3

0

Send dialog is not supported yet in android, so you have 3 options:

  • Wait for facebook to implement the dialog for android.
  • Try to open the dialog in a browser (the url for that is in the docs) in the mobile device.
  • Ask for the xmpp_login permission and add a xmpp client (i.e.: asmack) and with that you can implement your own "Send Message" dialog.
Sunil Mishra
  • 3,796
  • 1
  • 27
  • 40
0

If you are trying to send some message to friends than use WebDialog. Below is code which i use and working fine.

private void sendRequestDialog(String msg, String json) {
        Bundle params = new Bundle();
        params.putString("message", msg);
        params.putString("data", json);
        WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(
                context, session, params)).setOnCompleteListener(
                new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values,
                            FacebookException error) {

                        if (error != null) {
                            if (error instanceof FacebookOperationCanceledException) {
                                Toast.makeText(context, "Request cancelled",
                                        Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(context, "Network Error",
                                        Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            final String requestId = values
                                    .getString("request");
                            if (requestId != null) {
                                Toast.makeText(context, "Request sent",
                                        Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(context, "Request cancelled",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    }

                }).build();
        requestsDialog.show();
    }

And this is the format of a message which sends to friends

{
  "id": "493703870648580", 
  "application": {
    "name": "Send Requests How To", 
    "id": "403223126407920"
  }, 
  "to": {
    "name": "Chris Abe Colm", 
    "id": "100003086810435"
  }, 
  "from": {
    "name": "Christine Abernathy", 
    "id": "1424840234"
  }, 
  "data": "{\"badge_of_awesomeness\":\"1\",\"social_karma\":\"5\"}", 
  "message": "Learn how to make your Android apps social", 
  "created_time": "2012-10-07T17:29:57+0000"
}
ParikshitSinghTomar
  • 417
  • 1
  • 4
  • 28
0

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

enter image description here

You can send attachment with following mime types:

enter image description here

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

enter image description here

More documentation is on https://developers.facebook.com/docs/messenger/android

Piyush
  • 1,528
  • 2
  • 24
  • 39