asd*_*sda 5 android android-studio facebook-sdk-4.0
我想通过代码打开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;
Run Code Online (Sandbox Code Playgroud)
转到某人的 Facebook 个人资料。右键单击个人资料图片并复制链接地址。将其粘贴到文本编辑器上,您将在 URL 末尾看到“referrer_profile_id”参数。它是该用户的 Facebook ID。
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://messaging/" + FbUserID));
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
你可以像这样打开它,无需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();
}
Run Code Online (Sandbox Code Playgroud)