Skip to content

Instantly share code, notes, and snippets.

@sir4ju1
Last active December 28, 2015 21:29
Show Gist options
  • Save sir4ju1/7565437 to your computer and use it in GitHub Desktop.
Save sir4ju1/7565437 to your computer and use it in GitHub Desktop.
Facebook Like button for android
public static Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager()
.getPackageInfo("com.facebook.katana", 0); //Checks if FB is even installed.
return new Intent(Intent.ACTION_VIEW,
Uri.parse("fb://profile/254175194653125")); //Trys to make intent with FB's URI
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.facebook.com/sentiapps")); //catches and opens a url to the desired page
}
}
//USAGE
Intent facebookIntent = getOpenFacebookIntent(this);
startActivity(facebookIntent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment