Android facebook send message

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

Here is my code to send a message to a 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; } 

The following is a short error message:

enter image description here

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

+2
android facebook
Sep 04 '13 at 5:21
source share
3 answers

Send dialog is not yet supported on Android, so you have 3 options:

  • Wait for the dialog box for Android to appear on facebook.
  • Try opening a dialog box in your browser (the URL that is in the docs ) on your mobile device.
  • Request xmpp_login permission and add an xmpp client (for example: asmack ), and with this you can implement your own "Send message".
0
Sep 04 '13 at 7:05
source share
— -

If you are trying to send some kind of message to your friends, than using WebDialog. Below is the code that I use and work 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 message format that is sent 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" } 
0
Apr 25 '14 at 7:37
source share

You can use MessengerUtils from the latest facebook android android platform to send message with attachments.

enter image description here

You can send an attachment with the following mime types:

enter image description here

An example code for sending an image looks 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

Additional documentation is at https://developers.facebook.com/docs/messenger/android

0
06 Sep '16 at 16:32
source share



All Articles