Skip to content

Instantly share code, notes, and snippets.

@hoajb
Forked from layerlre/IntentFacebook.java
Created November 7, 2018 07:13
Show Gist options
  • Save hoajb/191e6db1e3ef853cb93f76c2f649c3c7 to your computer and use it in GitHub Desktop.
Save hoajb/191e6db1e3ef853cb93f76c2f649c3c7 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