from my Android app, I would like to open a link to a Facebook profile in the official Facebook app (if the app is installed, of course). For iPhone, there exists the fb://
URL scheme, but trying the same thing on my Android device throws an ActivityNotFoundException
.
Is there a chance to open a Facebook profile in the official Facebook app from code?
This works on the latest version:
Use this method:
public static Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/<id_here>"));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name_here>"));
}
}
This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser.
EDIT: since version 11.0.0.11.23 (3002850) Facebook App do not support this way anymore, there's another way, check the response below from Jared Rummler.