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

Open a facebook page from android app?

如何开始在手机上打开Facebook应用程序并导航到Facebook中的首选页面?

我尝试过:

1
2
3
4
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana","com.facebook.katana.ProfileTabHostActivity");
intent.putExtra("extra_user_id","123456789l");
this.startActivity(intent);

好吧,无论我写什么" " 1234567891 ",它始终会导航到我的页面。永远对我而言,对其他人而言。

我该怎么做?


这是最好,最简单的方法。
只需遵循代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public final void Facebook() {
        final String urlFb ="fb://page/"+yourpageid;
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(urlFb));

        // If Facebook application is installed, use that else launch a browser
        final PackageManager packageManager = getPackageManager();
        List<ResolveInfo> list =
            packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
        if (list.size() == 0) {
            final String urlBrowser ="https://www.facebook.com/pages/"+pageid;
            intent.setData(Uri.parse(urlBrowser));
        }

        startActivity(intent);
    }


我遇到了完全相同的问题,发送了用户ID,但由于某种原因,我的个人资料始终打开,而不是朋友的个人资料。

问题在于,如果您传递表示Facebook UID的Long对象的String或什至是Long基本类型,则该意图将无法在以后读取。您需要传递真实的Long

因此完整的代码是:

1
2
3
4
5
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setClassName("com.facebook.katana","com.facebook.katana.ProfileTabHostActivity");
    Long uid = new Long("123456789");
    intent.putExtra("extra_user_id", uid);
    startActivity(intent);

确定并希望对您有所帮助:-)

格言


尝试此代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
String facebookUrl ="https://www.facebook.com/<id_here>";
    try {
        int versionCode = getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
        if (versionCode >= 3002850) {
            Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
               startActivity(new Intent(Intent.ACTION_VIEW, uri));
        } else {
            Uri uri = Uri.parse("fb://page/<id_here>");
            startActivity(new Intent(Intent.ACTION_VIEW, uri));
        }
    } catch (PackageManager.NameNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
    }

此解决方案将不再起作用。新版的Facebook应用不再支持这些意图。看到这里的错误报告

新的解决方案是使用iPhone方案机制(是的,facebook决定在Android中支持iPhone机制,而不是Android的隐式意图机制)。

因此,要使用用户个人资料打开facebook应用,您需要做的是:

1
2
3
String facebookScheme ="fb://profile/" + facebookId;
Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
startActivity(facebookIntent);

如果您正在寻找其他操作,则可以将以下页面用于所有可用操作(/但是您必须对其进行测试,因为我没有找到有关此操作的Facebook官方出版物)