Open your facebook page from the Android app.

How can I start the intention to open the Facebook application on my phone and navigate to my preferred Facebook page?

I tried:

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);

Well, whatever I write in "1234567891", it always goes to my page. Always for me, and not otherwise.

How can i do this?

+4
source share
4 answers

I had exactly the same problem, I sent a user ID, but for some reason my profile always opened instead of my friend's profile.

, String Long, UID Facebook Long, . Long.

, :

    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);

, : -)

+4

.

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);
    }
+11

:

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)));
    }
+1

. facebook . .

The new solution is to use the iPhone schema mechanism (yes, facebook decided to support the iPhone mechanism in Android instead of the implicit Android intent mechanism).

So, to open a facebook application with a user profile, all you have to do is:

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

If you are looking for other actions, you can use the following page for all available actions (/ you should check this though, since I have not found an official facebook post about this)

0
source

All Articles