1

我创建了一个偏好,我想回到我的 Facebook 页面。我想单击用户可以选择在 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;
}
    });
4

1 回答 1

2

这就是我检查是否安装了谷歌地图的方式。修改为检查 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();
}
于 2013-07-26T12:20:16.377 回答