Open Facebook page from Android app?
This works on the latest version:
- Go to https://graph.facebook.com/<user_name_here> (https://graph.facebook.com/fsintents for instance)
- Copy your id
Use this method:
public static Intent getOpenFacebookIntent(Context context) { try { context.getPackageManager().getPackageInfo("com.facebook.katana", 0); return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/<id_here>")); } catch (Exception e) { return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name_here>")); }}
This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser.
EDIT: since version 11.0.0.11.23 (3002850) Facebook App do not support this way anymore, there's another way, check the response below from Jared Rummler.
In Facebook version 11.0.0.11.23 (3002850) fb://profile/
and fb://page/
no longer work. I decompiled the Facebook app and found that you can use fb://facewebmodal/f?href=[YOUR_FACEBOOK_PAGE]
. Here is the method I have been using in production:
/** * <p>Intent to open the official Facebook app. If the Facebook app is not installed then the * default web browser will be used.</p> * * <p>Example usage:</p> * * {@code newFacebookIntent(ctx.getPackageManager(), "https://www.facebook.com/JRummyApps");} * * @param pm * The {@link PackageManager}. You can find this class through {@link * Context#getPackageManager()}. * @param url * The full URL to the Facebook page or profile. * @return An intent that will open the Facebook page/profile. */public static Intent newFacebookIntent(PackageManager pm, String url) { Uri uri = Uri.parse(url); try { ApplicationInfo applicationInfo = pm.getApplicationInfo("com.facebook.katana", 0); if (applicationInfo.enabled) { // http://stackoverflow.com/a/24547437/1048340 uri = Uri.parse("fb://facewebmodal/f?href=" + url); } } catch (PackageManager.NameNotFoundException ignored) { } return new Intent(Intent.ACTION_VIEW, uri);}
Is this not easier?For example within an onClickListener?
try { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/426253597411506")); startActivity(intent);} catch(Exception e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/appetizerandroid")));}
PS. Get your id (the large number) from http://graph.facebook.com/[userName]