Skip to content Skip to sidebar Skip to footer

Android Facebook Send A Message

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 dial

Solution 1:

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.

Solution 2:

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

privatevoidsendRequestDialog(String msg, String json) {
        Bundle params = newBundle();
        params.putString("message", msg);
        params.putString("data", json);
        WebDialog requestsDialog = (newWebDialog.RequestsDialogBuilder(
                context, session, params)).setOnCompleteListener(
                newOnCompleteListener() {

                    @OverridepublicvoidonComplete(Bundle values,
                            FacebookException error) {

                        if (error != null) {
                            if (error instanceofFacebookOperationCanceledException) {
                                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"
}

Solution 3:

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

StringmimeType="image/jpeg";

// contentUri points to the content being shared to MessengerShareToMessengerParamsshareToMessengerParams=
        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

Post a Comment for "Android Facebook Send A Message"