0

I want to put a button which directs user to someone's personal profile page or a fan page in Android.

I may basically put the fan page's link to the button. However what I want is that the page should be open on the Facebook app which user already has on his phone.

In other words when I touch the button Facebook app will open and show the specific page, not the browser.

So, do I need to create a Facebook app to implement this?

Any help would be appreciated. Thanks in advance

user2870
  • 477
  • 7
  • 18

1 Answers1

2

The Android Facebook app responds to the fb:// protocol, so you can create a button that opens a page like this:

public void onClick(View arg0) {
    try{
        getBaseContext().getPackageManager().getPackageInfo("com.facebook.katana", 0);
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/[id]"));
    startActivity(intent);
    }catch(Exception e){
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://facebook.com/[yourpage]"));
        startActivity(intent);      
    }

}

This code will check if the Facebook app is installed (credits to Open Facebook page from Android app?) and if so, open the page there. Otherwise, it will open it in the browser.

Now, to actually get the page id, you will need to go to graph.facebook.com/[yourpageurl]. Your "page URL" is the last part of your Facebook URL (ie. http://facebook.com/thisparthere) when you are on the page. Once you find it and visit the graph page, copy the "id" field and that is what you need to put in your fb:// URL.

I tested this on Android 4.3 with the latest FB app, so my apologies if it doesn't work on other versions...

Community
  • 1
  • 1
T3KBAU5
  • 1,861
  • 20
  • 26