如何从我的应用程序创建到Facebook页面的意图?

问题描述:

这似乎是一个已成定局的问题,我想我已经可以轻松找到答案了,但是我发现的答案很旧,无法解决.如何从我的应用程序创建到Facebook页面的意图?如果打开了Facebook应用,我想这样做,否则请浏览器

It seemed a foregone question and I thought I could easily find an answer already, but the answers I found are very old and they do not work. How do I create a intent from my app to facebook page? I would like that if there is open the Facebook app, otherwise the browser

到目前为止,最好的解决方案是Rishav Singla的解决方案:

Up to now the best SOLUTION is that of Rishav Singla:

public static Intent getOpenFacebookIntent(Context context) {

    try {
        context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
        return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/<id_here>"));
    } catch (Exception e) {
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://www.facebook.com/<user_name_here>"));
    }
}

使用:

startActivity(getOpenFacebookIntent(getApplicationContext()));

...在attesa di altre soluzioni中

... in attesa di altre soluzioni

使用URL到Facebook在浏览器中打开

Use URL to facebook to Open it in browser

    String url = "https://www.facebook.com/ZambianWatchdog/";
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);