Skip to content

Instantly share code, notes, and snippets.

@layerlre
Last active January 9, 2023 15:02
Show Gist options
  • Save layerlre/163479670ac8e2bc512330193bcefd1c to your computer and use it in GitHub Desktop.
Save layerlre/163479670ac8e2bc512330193bcefd1c to your computer and use it in GitHub Desktop.
Open Facebook Page URL in Facebook app with Intent
....
public void startFacebook(String facebookUrl) {
try {
Uri uri = null;
int versionCode = getPackageManager()
.getPackageInfo("com.facebook.katana", 0)
.versionCode;
if (versionCode >= 3002850) {
facebookUrl = facebookUrl.toLowerCase().replace("www.", "m.");
if (!facebookUrl.startsWith("https")) {
facebookUrl = "https://" + facebookUrl;
}
uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
} else {
String pageID = facebookUrl.substring(facebookUrl.lastIndexOf("/"));
uri = Uri.parse("fb://page" + pageID);
}
Log.d(TAG, "startFacebook: uri = " + uri.toString());
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} catch (Throwable e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
}
}
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment