从我的android应用链接到fb应用中的页面 [英] link from my android app to a page in fb app

查看:149
本文介绍了从我的android应用链接到fb应用中的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在互联网上寻找了一段时间,但是还没有找到解决方案.

I've looked for a while on the internet, but haven't found a solution yet.

所以我的问题是:是否可以通过在我自己的android应用程序中单击列表项来在facebook应用程序中打开Facebook页面"x"?

So my question is : Is it possible to open a facebook page 'x' in the facebook app, from clicking on a listitem in my own android app?

因为现在我要在Web视图中链接到我的应用程序中的fb页面"x",所以最好打开fb应用程序并直接转到页面"x".

Because now i'm linking to the fb page 'x' in my app in a webview, and it would be better to open the fb app and directly go to the page 'x'.

编辑,我找到了一个解决方案,但尚未完全解决.它现在会打开facebook应用程序,但是由于我要显示的页面不是配置文件,而是页面,因此在facebook应用程序中显示错误. 这是代码:

EDIT i have found a solution, but it is not working completely yet. it opens the facebook app now, but as the page that I want to display is not a profile but a page it gives an error in the facebook app. here is the code:

   public static Intent getOpenFacebookIntent(Context context) {

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

这不起作用.如果我将第一个URI解析编辑为

this does'nt work. if i edit the first URI parse to

Uri.parse("fb://profile/myprofileid")

然后我可以在应用程序中打开我的个人资料.但是我要显示的页面不是我自己的页面.我可以问他们一些信息,如果我是保密的话,那是我认识的人.

then I am able to open my profile in the app. but the page I want to display is not my own page. And I could ask them info,if nesecaraly, as I know the people.

但是也许有人有一些想法可以使它起作用.

but maybe someone has some idea to get this to work.

推荐答案

好,所以我终于解决了.

Ok so I solved it eventually.

这是工作代码:

public static Intent getOpenFacebookIntent(Context context) {

       try {
        context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
        return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/5676133521"));
       } catch (Exception e) {
        return new Intent(Intent.ACTION_VIEW, Uri.parse("https://touch.facebook.com/androiddevs"));
       }
    }
}

要获取页面的ID,您只需在浏览器中转到Facebook中的页面,然后将"www"替换为"graph"即可.您将看到的第一行将是页面的ID.

to obtain the ID of a page you just go to the page in facebook in your browser, and then replace the 'www' to 'graph'. the firs line you'll see will be the ID of the page.

希望这对遇到我同样问题的人有所帮助!

hope this helps people who have the same problem i had !

这篇关于从我的android应用链接到fb应用中的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆