Open Facebook page from Android app?

前端 未结 26 3476
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 07:03

from my Android app, I would like to open a link to a Facebook profile in the official Facebook app (if the app is installed, of course). For iPhone, there exists the

26条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 07:49

    this is the simplest code for doing this

    public final void launchFacebook() {
            final String urlFb = "fb://page/"+yourpageid;
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(urlFb));
    
            // If a Facebook app is installed, use it. Otherwise, launch
            // a browser
            final PackageManager packageManager = getPackageManager();
            List list =
                packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() == 0) {
                final String urlBrowser = "https://www.facebook.com/"+pageid;
                intent.setData(Uri.parse(urlBrowser));
            }
    
            startActivity(intent);
        }
    

提交回复
热议问题