【问题标题】:Android: Open Facebook profile in app from usernameAndroid:从用户名在应用中打开 Facebook 个人资料
【发布时间】:2016-09-15 10:46:36
【问题描述】:

如何从用户名打开 Facebook 个人资料?或者我应该在 Android 中使用哪个请求来获取(和打开)Facebook 个人资料。

Intent intent;

try {
    activity.getPackageManager()
            .getPackageInfo("com.facebook.katana", 0); // Checks if FB is even installed.
    intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("fb://profile/" + famous)); // Trys to make intent with FB's URI
} catch (Exception e) {
    intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("https://www.facebook.com/" + famous)); // catches and opens a url to the desired page
}

activity.startActivity(intent);

尝试过,但无法使用用户名(转到用户的 - 已登录的用户 - 墙)和 id(静态插入,显示错误 - 无法加载此配置文件)...

【问题讨论】:

    标签: android facebook android-studio android-intent


    【解决方案1】:

    您可以使用以下打开,因为fb://profile/fb://page/不再起作用,但可以使用fb://facewebmodal/f?href=[YOUR_FACEBOOK_PAGE]

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

    url:Facebook 页面或个人资料的完整 URL。

    pm : Context#getPackageManager()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多