Skip to content

Instantly share code, notes, and snippets.

@captswag
Created May 7, 2015 11:41
Show Gist options
  • Save captswag/d5b7c0f4246eace41c40 to your computer and use it in GitHub Desktop.
Save captswag/d5b7c0f4246eace41c40 to your computer and use it in GitHub Desktop.
Android, java code for opening facebook profile of a user in the facebook application, if the user has it installed, or open the profile in the web browser.
/*
* Go to https://graph.facebook.com/<user_name_here>
* Copy your id
* This will open up facebook app if the user has it installed
* Otherwise it will open facebook in the browser
*/
public Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<id_here>"));
}
catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name>"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment