7

Possible Duplicate:
Open Facebook page from Android app?

Does the Android Facebook app have Intents that other apps can use to start the Facebook app and goto a specific page?

For example, when someone clicks a certain button in my app, I want them to be taken to Facebook to a specific company's public Facebook page. Starting a web browser activity for this is easy, but more than likely the user is not logged in the browser etc...

I was thinking it would be nice if I could instead use an Intent (if one exists...) to start up the Facebook app and take the user to the specific page in the app. That way the user is already logged in and can interact with the page, Like it, etc...

Does an Intent like this exist? If so, where would I find more information on it? I've been looking through Facebook's developer documentation but I'm not seeing anything about this.

Community
  • 1
  • 1
Jake Wilson
  • 88,616
  • 93
  • 252
  • 370

1 Answers1

12
  1. Go to https://graph.facebook.com/<user_name_here> (https://graph.facebook.com/fsintents for instance)
  2. Copy your id
  3. Use this method:

    public static Intent getOpenFacebookIntent(Context context) {
    
       try {
        context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
        return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<id_here>"));
       } catch (Exception e) {
        return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name_here>"));
       }
    }
    

This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser.

joaomgcd
  • 5,287
  • 4
  • 28
  • 39
  • Interesting. Does this actually open and use the Facebook app? Or does it open Facebook in the browser? – Jake Wilson Apr 18 '12 at 17:12
  • Sorry, should have explained that. This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser. – joaomgcd Apr 19 '12 at 14:38
  • @joaomgcd Is it possible to link to a specific message this way as well? – Anders Metnik Jun 21 '12 at 07:03
  • Didn't exactly understood what context.getPackageManager().getPackageInfo("com.facebook.katana", 0); do. You don't use its return value – Nativ Apr 30 '13 at 09:04
  • @powerX it's just a way to verify that the "com.facebook.katana" package exists on the system. – joaomgcd May 03 '13 at 11:26
  • The question asked for a facebook page. Instead of 'profile' use 'page' get all the intents here http://binwaheed.blogspot.com.ar/2014/06/android-open-facebook-official-app-from.html – Kennedy Nyaga Feb 20 '15 at 09:42