Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening facebook app on specified profile page

Tags:

I'm trying to use some code from SO but it fails:

Those are uri's supposed to open the right section of the app.

facebook://facebook.com/info?user=544410940     (id of the user. "patrick.boos" won't work)
facebook://facebook.com/wall?user=544410940   (will only show the info if you have added it as 

What I want is to open facebook app on a profile I've specified. This is a code that I'm trying. The number is UID of the profile.

        String uri = "facebook://facebook.com/wall?user=417079614970109"; 
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        startActivity(intent);

Is it depreciated or what? How do I accomplish such task now?

like image 235
Jacek Kwiecień Avatar asked May 28 '12 17:05

Jacek Kwiecień


1 Answers

Actually it looks like this. These URIs only work with the most recent version of the facebook app. That's why we try catch.

public static Intent getOpenFacebookIntent(Context context) {

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

In your Activity, to open it, call it like so:

Intent facebookIntent = getOpenFacebookIntent(this);
startActivity(facebookIntent);
like image 146
Zaid Daghestani Avatar answered Sep 30 '22 02:09

Zaid Daghestani