在安卓系统中打开 Facebook Messenger

5

我想通过代码打开Facebook Messenger。我该如何获取Facebook ID?

我的应用程序中有Facebook SDK,并且我为每个用户保存了Facebook ID,但它与我需要的不同。

这是我的方法:

// Make sure the Facebook Messenger for Android client is installed
        boolean isFBInstalled = isAppInstalled("com.facebook.orca");

        if (!isFBInstalled) {
            Toast.makeText(this,"Facebook messenger isn't installed. Please download the app first.", Toast.LENGTH_SHORT)
                    .show();
        }

        else {
            // Create the Intent
            Uri uri = Uri.parse("fb-messenger://user/");
            uri = ContentUris.withAppendedId(uri,Long.valueOf(facebookIDhere);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);

            try {
                startActivity(intent);
            }

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

        return;

3个回答

5

前往某人的Facebook个人资料。右键单击个人资料图片并复制链接地址。将其粘贴到文本编辑器中,您会看到URL末尾的“referrer_profile_id”参数。这是该用户的Facebook ID。

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

@KonstantinKonopko 哪个部分? - kmchmk

2
您可以直接打开它,而不需要 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();
}

1
我想给一个特定的用户打开一条信息。我有一个用户列表,因此我想为该用户打开Facebook Messenger聊天。 - asda sda

0
首先,检查应用程序是否存在于设备中并编写以下代码以打开。
Intent intent = activity.getPackageManager().getLaunchIntentForPackage("com.facebook.orca");
activity.startActivity(intent);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接