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
As of March 2020 this works perfectly.
private void openFacebookPage(String pageId) {
String pageUrl = "https://www.facebook.com/" + pageId;
try {
ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo("com.facebook.katana", 0);
if (applicationInfo.enabled) {
int versionCode = getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
String url;
if (versionCode >= 3002850) {
url = "fb://facewebmodal/f?href=" + pageUrl;
} else {
url = "fb://page/" + pageId;
}
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} else {
throw new Exception("Facebook is disabled");
}
} catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(pageUrl)));
}
}