我想通过代码打开facebook messenger。我如何获得Facebook ID? 我在我的应用程序上有facebook SDK,我为每个用户保存了facebookId但是和我需要的不一样
这是我的方法:
// 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;
答案 0 :(得分:1)
您可以在没有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 :(得分:0)
首先,检查应用程序是否存在于设备中,然后编写以下行以打开。
Intent intent = activity.getPackageManager().getLaunchIntentForPackage("com.facebook.orca");
activity.startActivity(intent);
答案 2 :(得分:0)
转到某人的Facebook个人资料。右键单击配置文件图片并复制链接地址。将其粘贴到文本编辑器上,您将在URL的末尾看到“referrer_profile_id”参数。这是该用户的Facebook ID。
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://messaging/" + FbUserID));
startActivity(i);