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

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

问题描述:

从我的 Android 应用程序中,我想在官方 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 应用中打开 Facebook 个人资料?

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

在 Facebook 版本 11.0.0.11.23 (3002850) fb://profile/fb://page/ 不再起作用.我反编译了 Facebook 应用,发现你可以使用 fb://facewebmodal/f?href=[YOUR_FACEBOOK_PAGE].这是我在生产中使用的方法:

In Facebook version 11.0.0.11.23 (3002850) fb://profile/ and fb://page/ no longer work. I decompiled the Facebook app and found that you can use fb://facewebmodal/f?href=[YOUR_FACEBOOK_PAGE]. Here is the method I have been using in production:

/**
 * <p>Intent to open the official Facebook app. If the Facebook app is not installed then the
 * default web browser will be used.</p>
 *
 * <p>Example usage:</p>
 *
 * {@code newFacebookIntent(ctx.getPackageManager(), "https://www.facebook.com/JRummyApps");}
 *
 * @param pm
 *     The {@link PackageManager}. You can find this class through {@link
 *     Context#getPackageManager()}.
 * @param url
 *     The full URL to the Facebook page or profile.
 * @return An intent that will open the Facebook page/profile.
 */
public static Intent newFacebookIntent(PackageManager pm, String url) {
  Uri uri = Uri.parse(url);
  try {
    ApplicationInfo applicationInfo = pm.getApplicationInfo("com.facebook.katana", 0);
    if (applicationInfo.enabled) {
      // http://*.com/a/24547437/1048340
      uri = Uri.parse("fb://facewebmodal/f?href=" + url);
    }
  } catch (PackageManager.NameNotFoundException ignored) {
  }
  return new Intent(Intent.ACTION_VIEW, uri);
}