Add “Like Us on Facebook” button to your Android App

It’s really a good idea to include the link to your Facebook page in the Android app. It will help you to keep in touch with the users of your app.

Below is the code you should put in the click event of the “Like Us on Facebook” button.

String fbPageId = "149483785425721";
String fbPageUrl = "https://www.facebook.com/bmicalculatorapp";

try {
  getPackageManager().getPackageInfo("com.facebook.katana", 0);
  Intent fb = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + fbPageId));
  startActivity(fb);
} catch (Exception e) {
  Intent fb = new Intent(Intent.ACTION_VIEW,  Uri.parse(fbPageUrl));
  startActivity(fb);
}

You just need to replace the fbPageId and fbPageUrl in above code. You can find the page id of your Facebook page in Your Page -> Settings -> Page Info section.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s