user4106398
user4106398

Reputation:

correct way to call facebook page in android?

I'm trying to open a facebook page using the facebook app if the user has facebook app installed, or use browser instead if they do not. I tried the following code:

    public static String FACEBOOK_URL = "https://www.facebook.com/Samsung";
    public static String FACEBOOK_PAGE_ID = "Samsung";

    //method to get the right URL to use in the intent
    public String getFacebookPageURL(Context context) {
        PackageManager packageManager = context.getPackageManager();
        try {
            int versionCode = packageManager.getPackageInfo("com.facebook.katana", 0).versionCode;
            if (versionCode >= 3002850) { //newer versions of fb app
                return "fb://facewebmodal/f?href=" + FACEBOOK_URL;

            } else { //older versions of fb app
                return "fb://page/" + FACEBOOK_PAGE_ID;
            }
        } catch (PackageManager.NameNotFoundException e) {
            return FACEBOOK_URL; //normal web url
        }
    }

It kind of works. if the facebook app is not installed, it opens the page in the browser correctly. However if the facebook app is installed, it only goes to a feed of the facebook page's activity, it doens't actually display the facebook page with the "like/share" buttons and the logo.

I tried getting rid of

return "fb://facewebmodal/f?href=" + FACEBOOK_URL;

and replacing it with just

return "fb://page/" + FACEBOOK_PAGE_ID;

which I heard works on all versions of the app, not just the new version, but no dice. When using that method on the most recent version of facebook app, it does not load the facebook page, only the logged in user's home page.

Any ideas? I've scoured stackoverflow for this but only found the above methods. I'm guessing facebook changed something recently in their app.

Upvotes: 1

Views: 47

Answers (1)

user4106398
user4106398

Reputation:

Figured it out. For PAGE_ID I was using the page ID as shown in a browser, which was incorrect. I used a numeric page ID and it worked.

Upvotes: 1

Related Questions