Open a facebook page from android app?

前端 未结 4 550
闹比i
闹比i 2020-12-30 16:20

How can I start an intent to open a Facebook application on a phone and navigate to the prefered page in Facebook?

I tried:

Intent intent = new Inten         


        
4条回答
  •  悲&欢浪女
    2020-12-30 16:51

    Here is the best and simple way to do it. Just follow the code

    public final void Facebook() {
            final String urlFb = "fb://page/"+yourpageid;
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(urlFb));
    
            // If Facebook application is installed, use that else 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/pages/"+pageid;
                intent.setData(Uri.parse(urlBrowser));
            }
    
            startActivity(intent);
        }
    

提交回复
热议问题