【问题标题】:Open a Facebook post URL in android Facebook app programmatically以编程方式在 android Facebook 应用程序中打开 Facebook 帖子 URL
【发布时间】:2020-06-01 08:40:26
【问题描述】:

我正在编写一个可以打开 Facebook 帖子网址的 android - java 应用程序 (例如:https://www.facebook.com/BaHangXom.0/videos/2377836809193490)。 我尝试了一些方法来有意启动 Facebook 应用,但没有成功。

    Intent intent =  new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=" + "https://www.facebook.com/BaHangXom.0/videos/2377836809193490"));
    intent.setPackage("com.facebook.katana");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

你能告诉我任何想法吗? 非常感谢。

【问题讨论】:

标签: java android facebook android-intent mobile


【解决方案1】:

直接打开网址:

Intent intent =  new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/BaHangXom.0/videos/2377836809193490"));
startActivity(intent);

这是最简单和通用的方式:用户将能够选择(并记住选择)是否要通过主 Facebook 应用程序、Facebook lite 或浏览器打开链接。

【讨论】:

  • 有什么方法可以不用用户选择直接打开facebook应用?
【解决方案2】:

您可以使用以下代码打开 facebook 应用:

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://stackoverflow.com/a/24547437/1048340
      uri = Uri.parse("fb://facewebmodal/f?href=" + url);
    }
  } catch (PackageManager.NameNotFoundException ignored) {
  }
  return new Intent(Intent.ACTION_VIEW, uri);
}

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    相关资源
    最近更新 更多