如果安装了Facebook应用程序,则Android打开Facebook页面链接,

问题描述:

如何在Facebook App中打开Facebook页面链接(如果已安装),以及是否未安装该应用,请在android的默认浏览器中打开

how to open Facebook page link in Facebook App if installed , and if the app is not installed open in default browser in android ??

我尝试了此代码,但无法正常工作?

i tried this code but its not working ??

     Face.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = null;
            String Facebook = dbList.get(0).getFacebook().toString();
            try {
                // get the Twitter app if possible
                getPackageManager().getPackageInfo("com.facebook.android", 0);
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" +Facebook));
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            } catch (Exception e) {
                // no Twitter app, revert to browser
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/?hl=en"));
            }
            startActivity(intent);
        }
    });

使用此代码,您可以打开用户个人资料

public static void opneFacebookProfile(Activity activity, String id) {
        Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
        String facebookUrl = getFacebookPageURL(activity, id);
        facebookIntent.setData(Uri.parse(facebookUrl));
        activity.startActivity(facebookIntent);
    }