Open Facebook Messenger in Android

前端 未结 3 407
盖世英雄少女心
盖世英雄少女心 2021-01-30 03:20

I want to open facebook messenger by code. How I can get the facebook ID?? I have the facebook SDK on my app and I saved for every user the facebookId but is not the same as I n

相关标签:
3条回答
  • 2021-01-30 03:59

    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();
    }
    
    0 讨论(0)
  • 2021-01-30 04:08

    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);
    
    0 讨论(0)
  • 2021-01-30 04:21

    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);
    
    0 讨论(0)
提交回复
热议问题