How to launch a Facebook Page in native Facebook app or browser from your android app

face

In this tutorial we are going to write a function to launch our apps Facebook page from a click event.

Before implementing this we need to obtain Facebook page ID which we need to launch.

How to get Facebook page ID

Its very simple,  First navigate to your Facebook page then look for the number after page name in URL

Example – It looks some thing like this  “(https://www.facebook.com/Funny-Troll-Time-App-1136754489778781/)” copy this Facebook Page ID.

Now we can move to Android studio and copy paste the following code

public void facebook()
{
    boolean installed = appInstalledOrNot("com.facebook.katana");                  //
    if(installed)                                                                  // We check whether Facebook app is installed or not
       {                                                                             
        String facebookID = "1136754489778781";
        final String url = "fb://page/" + facebookID;
        Intent facebookAppIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        facebookAppIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
        startActivity(facebookAppIntent);
      }
    else                                                                           // If its not found we launch it in browser
      {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/Funny-Troll-Time-App-1136754489778781/")));
      }
 }