在Facebook应用和浏览器之间选择?

时间:2013-07-26 11:54:19

标签: java android facebook facebook-android-sdk

我创建了一个偏好设置,我想回到我的脸书页面。我想点击一个用户可以选择在Facebook应用程序和浏览器之间进行选择。现在直接成为浏览器的一部分。代码是:

Facebook = (Preference) this.findPreference("facebook");
Facebook.setOnPreferenceClickListener( new OnPreferenceClickListener() {
    public boolean onPreferenceClick (Preference preference) {

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/MyPageName"));
startActivity(browserIntent);
return false;
}
    });

1 个答案:

答案 0 :(得分:2)

这是我检查Google地图是否已安装的方法。已修改以检查Facebook应用程序状态。

// CHECK IF THE FACEBOOK APP IS INSTALLED
PackageManager pkManager = activity.getPackageManager();
try {
    PackageInfo pkgInfo = pkManager.getPackageInfo("com.facebook.katana", 0);
    String getPkgInfo = pkgInfo.toString();

    if (getPkgInfo.equals("com.facebook.katana"))   {
        // OPEN THE PAGE IN THE FACEBOOK APP
        String strPage = "fb://profile/" + YOUR_PAGE_ID;

        // CHECK IF THE "fb://profile/" IS CORRECT | REPLACE WITH "fb://page/"
        // NOT ENTIRELY SURE WHICH ONE WORKS

        Intent showPageInFB = new Intent(Intent.ACTION_VIEW, Uri.parse(strPage)); 
        startActivity(showPageInFB );
    } else {
        // OPEN THE PAGE IN A BROWSER
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/MyPageName"));
        startActivity(browserIntent);
    }
} catch (NameNotFoundException e) {
    e.printStackTrace();
}