YoniR YoniR - 1 month ago 20
Java Question

Android - Java - Intent to send facebook chat message (facebook disabled xmpp)

***Facebook deprecated xmpp api.

Is there a way to open an intent (or pass data to fb) to send chat message on android device?
Facebook & Messenger apps installed on the device.

Thanks :-)

Answer

You need to pass uri to the intent Here 100005727832736 is the user id of the person who you want to message to

Uri uri = Uri.parse("fb-messenger://user/100005727832736");

Here is my sample code

Uri uri = Uri.parse("fb-messenger://user/100005727832736");

Intent toMessenger= new Intent(Intent.ACTION_VIEW, uri);
startActivity(toMessenger);
try {
        startActivity(toMessenger);
    } 
catch (android.content.ActivityNotFoundException ex) 
    {
        Toast.makeText(context, "Please Install Facebook Messenger",    Toast.LENGTH_LONG).show();
}
}

This is what worked for me and i haven not tested this for some time now.