skip to Main Content

***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 🙂

2

Answers


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

    Login or Signup to reply.
  2. To launch facebook app let urlString = “fb://page/your_fb_page_id”

    To launch facebook messenger let urlString = “fb-messenger://user/your_fb_page_id”

    FB page id is usually numeric. To get it, goto Find My FB ID input your profile url, something like http://www.facebook.com/edgedevstudio then click “Find Numberic ID”.

    Voila, you now have your fb numeric id. replace “your_fb_page_id” with the generated Numeric ID

     val intent = Intent(Intent.ACTION_VIEW, Uri.parse(urlString))
     if (intent.resolveActivity(packageManager) != null) //check if app is available to handle the implicit intent
     startActivity(intent)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search