通过 Facebook 应用程序而不是浏览器打开 Facebook 页面时出现问题

Issue in opening Facebook page via Facebook Application instead of Browser

我需要在我安装的 Facebook 应用程序中打开 Facebook 页面。我为此调用了以下函数:

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));
    }
}

但是,我的 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)

我应该怎么做才能完成任务?谢谢

您的问题是 link 格式...您应该使用:fb://facewebmodal/f?href=

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=https://www.facebook.com/mypage"));

检查他是否有应用程序,然后使用上面的 url 格式,否则将他重定向到浏览器:

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);