从Android应用程序打开的Facebook页面?

从Android应用程序打开的Facebook页面?

问题描述:

这是我的Andr​​oid应用程序,我想开一个链接到Facebook的个人资料在官方Facebook应用程序(如果已安装的应用程序,当然)。对于iPhone,存在着 FB:// URL方案,而是试图在Android设备上同样的事情会引发 ActivityNotFoundException

from my Android app, I would like to open a link to a Facebook profile in the official Facebook app (if the app is installed, of course). For iPhone, there exists the fb:// URL scheme, but trying the same thing on my Android device throws an ActivityNotFoundException.

有机会在官方的Facebook应用程序从code。打开一个Facebook的个人资料?

Is there a chance to open a Facebook profile in the official Facebook app from code?

这适用于最新的版本:

  1. 到https://graph.facebook.com/<user_name_here> ( https://graph.facebook.com/fsintents 例如)
  2. 复制你的ID
  3. 使用此方法:

  1. Go to https://graph.facebook.com/<user_name_here> (https://graph.facebook.com/fsintents for instance)
  2. Copy your id
  3. Use this method:

public static Intent getOpenFacebookIntent(Context context) {

   try {
    context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
    return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/<id_here>"));
   } catch (Exception e) {
    return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name_here>"));
   }
}

如果用户已经安装它这将打开Facebook的应用程序。否则,将在浏览器中打开实

This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser.