-
-
Save hoajb/191e6db1e3ef853cb93f76c2f649c3c7 to your computer and use it in GitHub Desktop.
Open Facebook Page URL in Facebook app with Intent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
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