Intent to open profile with the facebook app using Page ID, Android?


I am trying to open a facebook profile with a button, but I have tried and always open with the browser and not with the facebook app, someone can help me please, so I have it at this time.

    protected void onCreate(Bundle savedInstanceState) {
    Uri uri = Uri.parse("");
    Intent intent = new Intent(Intent.ACTION_VIEW,uri);
    }catch(Exception e){
    }finally {

asked by Ivan Alfredo 10.05.2017 в 15:56

2 answers


For this you need the "Facebook page id", which is obtained in this way:

  • From the page go to "About"
  • Go to "More Info"
  • There will be the "Facebook Page ID"

To open the application, it is done like this:

 String facebookId = "fb://page/<Facebook Page ID>"; //*Los signos < y > no van!
 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookId )));

I recommend you validate the case in which the installed application does not exist. In this case, you will open the web page if you can not find the application installed:

String facebookId = "fb://page/<Facebook Page ID>";
String urlPage = "";

     try {
          startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookId )));
        } catch (Exception e) {
         Log.e(TAG, "Aplicación no instalada.");
         //Abre url de pagina.
         startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
answered by 10.05.2017 / 17:53

This could work:

public static String FACEBOOK_URL = "";
public static String FACEBOOK_PAGE_ID = "YourPageName";

//método que obtiene la verdadera URL
public String getFacebookPageURL(Context context) {
    PackageManager packageManager = context.getPackageManager();
    try {
        int versionCode = packageManager.getPackageInfo("com.facebook.katana", 0).versionCode;
        if (versionCode >= 3002850) { //versiones nuevas de facebook
            return "fb://facewebmodal/f?href=" + FACEBOOK_URL;
        } else { //versiones antiguas de fb
            return "fb://page/" + FACEBOOK_PAGE_ID;
    } catch (PackageManager.NameNotFoundException e) {
        return FACEBOOK_URL; //normal web url

The method returns the correct facebook URL whether you have the app installed or not.

After the Intent is launched

Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getFacebookPageURL(this);

I hope it serves you

answered by 10.05.2017 в 16:19