Q:

Issue in opening Facebook page via Facebook Application instead of Browser

I need to open Facebook page in my installed Facebook Application. I have called the below function for that :  
private void loadFacebookUrl() {
    if (Constant.isOnline(AboutActivity.this)) {
        try {
            if (appInstalledOrNot(AboutActivity.this, "com.facebook.katana")) {
                this.getPackageManager().getPackageInfo("com.facebook.katana", 0);
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/MyPage/")).setPackage("com.facebook.katana"));
            } else {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.facebook.katana")));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Constant.displayToast(AboutActivity.this, getResources().getString(R.string.msg_internet));
    }
}

But, I am getting the following exception in my Logcat: 
    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://www.facebook.com/... pkg=com.facebook.katana }
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1514)
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:     at android.app.Activity.startActivityForResult(Activity.java:3978)
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:     at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:     at android.app.Activity.startActivityForResult(Activity.java:3939)
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
07-07 14:19:24.071 5094-5094/com.app.thelist W/System.err:     at android.app.Activity.startActivity(Activity.java:4262)
07-07 14:19:24.071 5094-5094/com.app.thelist W/System.err:     at android.app.Activity.startActivity(Activity.java:4230)
07-07 14:19:24.071 5094-5094/com.app.thelist W/System.err:     at com.app.thelist.activity.AboutActivity.loadFacebookUrl(AboutActivity.java:98)
07-07 14:19:24.071 5094-5094/com.app.thelist W/System.err:     at com.app.thelist.activity.AboutActivity.onClick(AboutActivity.java:76)

What should I have to do to get the task done? Thanks.

A:

your problem is in the link format... you should use: fb://facewebmodal/f?href=
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=https://www.facebook.com/mypage"));

check if he has the app, then use the above url format, else redirect him to the browser:
String pageurl = "https://www.facebook.com/mypage";
boolean hasFacebook = appInstalledOrNot(AboutActivity.this, "com.facebook.katana");
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse((hasFacebook?("fb://facewebmodal/f?href="):"") + pageurl));
startActivity(i);

