20

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?

Jacek Kwiecień
  • 12,397
  • 20
  • 85
  • 157
  • possible duplicate of [Open Facebook page from Android app?](http://stackoverflow.com/questions/4810803/open-facebook-page-from-android-app) – rds Jan 22 '13 at 09:51

7 Answers7

55

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);
Zaid Daghestani
  • 8,555
  • 3
  • 34
  • 44
  • thank you very much. Much of the threads got depreciated I suppose. There goes my facebook like sentiapps :) – Jacek Kwiecień May 28 '12 at 17:38
  • How do you call this method? for example getOpenFacebookIntent (??) - what goes there for the context? – gbotha Aug 03 '12 at 22:54
  • 2
    Just to clarify the number after profile is the users facebook id. If you only have a username you can get the id from the id field from http://graph.facebook.com/[userName] – Nicholas Harlen Feb 24 '13 at 23:01
  • @ZedScio When i try to use "fb://profile/" to open a page in facebook app it opens up the page but do not show the like button. Instead a subscribe button is shown. Can you tell me why this issue is happening. My question is at [this link](http://stackoverflow.com/questions/15563908/cannot-see-like-option-in-facebook-page-from-android-device) – glo Mar 22 '13 at 15:47
  • With this approach I can open the desired page in my FB app, thanks for that. But then I face a problem, when I try to "Follow" or "Like" that page, it shows me a toast - "There was a problem following this Profile. Please try again later." I wonder why it could be happening. Any suggestion? – Khobaib Nov 18 '13 at 11:00
  • & here is the answer of that issue, use "page" instead of "profile"- http://stackoverflow.com/a/15872383/1433187 – Khobaib Nov 18 '13 at 11:04
  • 1
    you should also add `intent.setPackage("com.facebook.katana");` it makes the facebook activity open faster! – RCB Mar 31 '14 at 10:08
  • 1
    As specified in Jareds answer in http://stackoverflow.com/questions/4810803/open-facebook-page-from-android-app there is a new adress for the intetnt to open the fb app in version 11+: fb://facewebmodal/f?href=[FACEBOOK_URL] and enter the normal web url there. – Erik Melkersson Jan 26 '16 at 12:18
13

This no longer works

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/someProfile"));

Please try this instead

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=https://www.facebook.com/someProfile"));
Tristan Richard
  • 3,385
  • 1
  • 15
  • 17
11

Is this not easier? For example within an onClickListener?

try { 
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/426253597411506"));
    startActivity(intent);
} catch(Exception e) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/appetizerandroid")));    
}   

PS. Get your id (the large number) from http://graph.facebook.com/[userName]

juanjo
  • 3,737
  • 3
  • 39
  • 44
John
  • 878
  • 11
  • 21
2

There are so many question about this but this code is worked for me.Facebook changed there policy so for more detail please check this Facebook official GRAPH API EXPLORER PAGE

Intent intent = null;
    try {
        getPackageManager().getPackageInfo("com.facebook.katana", 0);
        String url = "https://www.facebook.com/"+idFacebook;
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href="+url));
    } catch (Exception e) {
        // no Facebook app, revert to browser
        String url = "https://facebook.com/"+idFacebook;
        intent = new Intent(Intent.ACTION_VIEW);
        intent .setData(Uri.parse(url));
    }
    this.startActivity(intent);
Farmer
  • 4,093
  • 3
  • 23
  • 47
1

For now it is not possible, Facebook has been removed this functionality

Jemo Mgebrishvili
  • 5,187
  • 7
  • 38
  • 63
1

To do this we need the "Facebook page id", you can get it :

  • from the page go to "About".
  • go to "More Info" section.

introducir la descripción de la imagen aquí

To opening facebook app on specified profile page,

you can do this:

 String facebookId = "fb://page/<Facebook Page ID>";
  startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookId)));
Community
  • 1
  • 1
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
1

For facebook page use like this: http://fb://page/87268309621xxxx For personal id use like this: http://fb://profile/87268309621xxxx

abir-cse
  • 507
  • 3
  • 12