Last active
January 9, 2023 15:02
-
-
Save layerlre/163479670ac8e2bc512330193bcefd1c 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