Open Facebook Page From Android App (in Facebook Version > V11)
I used to open my facebook page from my app using the below code, but this does not work anymore starting facebook v11.0.0.11.23 released on June 21, 2014, any idea how to open the
Solution 1:
In Facebook version 11.0.0.11.23 (3002850) fb://profile/ and fb://page/ are no longer supported. I decompiled the Facebook app and was able to come up with the following solution:
StringfacebookUrl="https://www.facebook.com/JRummyApps";
try {
intversionCode= getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) {
Uriuri= Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
startActivity(newIntent(Intent.ACTION_VIEW, uri));;
} else {
// open the Facebook app using the old method (fb://profile/id or fb://page/id)
startActivity(newIntent(Intent.ACTION_VIEW, Uri.parse("fb://page/336227679757310")));
}
} catch (PackageManager.NameNotFoundException e) {
// Facebook is not installed. Open the browser
startActivity(newIntent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
}
Edit: It has been some time and it looks like fb://profile and fb://page are no longer supported. Below is the method I have been using in production:
/**
* Intent to open the official Facebook app. If the Facebook app is not installed then the
* default web browser will be used.</p>
*
* Example usage:</p>
* <code>newFacebookIntent(context.getPackageManager(), "https://www.facebook.com/JRummyApps");</code></p>
*
* @param pm
* Instance of the {@link PackageManager}.
* @param url
* The full URL to the Facebook page or profile.
* @return An intent that will open the Facebook page/profile.
*/publicstatic Intent newFacebookIntent(PackageManager pm, String url) {
Uri uri;
try {
pm.getPackageInfo("com.facebook.katana", 0);
// http://stackoverflow.com/a/24547437/1048340
uri = Uri.parse("fb://facewebmodal/f?href=" + url);
} catch (PackageManager.NameNotFoundException e) {
uri = Uri.parse(url);
}
returnnew Intent(Intent.ACTION_VIEW, uri);
}
Post a Comment for "Open Facebook Page From Android App (in Facebook Version > V11)"