Open Facebook Messenger in Android

核能气质少年 提交于 2019-12-02 14:45:48

Go to someone's facebook profile. Right click on the profile picture and copy the link address. Paste it on a text editor and you will see the "referrer_profile_id" parameter at the end of the URL. It is the facebook ID of that user.

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://messaging/" + FbUserID));
startActivity(i);

You can simply open it like this without an FB ID

Intent intent= new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hello");
intent.setType("text/plain");
intent.setPackage("com.facebook.orca");

try
{
    startActivity(intent);
}
catch (ActivityNotFoundException ex) 
{
    Toast.makeText(this,
           "Oups!Can't open Facebook messenger right now. Please try again later.", 
            Toast.LENGTH_SHORT).show();
}

First, check the app is existed in device or not and write the following lines to open.

Intent intent = activity.getPackageManager().getLaunchIntentForPackage("com.facebook.orca");
activity.startActivity(intent);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!