打开Facebook页面从Android应用程序(在Facebook的版本> V11) [英] Open facebook page from android app (in facebook version > v11)

查看:515
本文介绍了打开Facebook页面从Android应用程序(在Facebook的版本> V11)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前使用下面的code我的应用程序打开我的Facebook页面,但这不工作了开始发布6月21日,2014年,任何想法如何,在打开页面的Facebook v11.0.0.11.23新的Facebook应用程序? 需要注意的是,现在打开Facebook的应用程序,但不打开指定的网页,它使用了最新的更新之前工作得很好

 公共无效openFacebookPage(){
    意向意图= NULL;
    尝试 {
        。context.getPackageManager()getPackageInfo(com.facebook.katana,0);
        意图=新的意图(Intent.ACTION_VIEW,Uri.parse(FB://页/<这里的id>中));
        //尝试,这也
        //意图=新的意图(Intent.ACTION_VIEW,Uri.parse(FB://资料/<这里的id>中));
    }赶上(例外五){
        意图=新的意图(Intent.ACTION_VIEW,Uri.parse(https://www.facebook.com/<name这里&GT;));
    }
    context.startActivity(意向);
}
 

解决方案

在Facebook的11.0.0.11.23版本(3002850)FB://资料/和FB://页/不再支持。我反编译的Facebook应用程序,并能想出以下解决方案:

 字符串facebookUrl =htt​​ps://www.facebook.com/JRummyApps;
尝试 {
    INT版本code = getPackageManager()getPackageInfo(com.facebook.katana,0).version code。
    如果(版本code取代; = 3002850){
        开放的我们的uri = Uri.parse(FB:// facewebmodal /˚FHREF =+ facebookUrl);
        startActivity(新意图(Intent.ACTION_VIEW,URI));;
    } 其他 {
        //使用旧方法打开Facebook应用程序(FB://资料/ ID或FB://页/ ID)
        startActivity(新意图(Intent.ACTION_VIEW,Uri.parse(FB://页/ 336227679757310)));
    }
}赶上(PackageManager.NameNotFoundException E){
    // Facebook的未安装。打开浏览器
    startActivity(新意图(Intent.ACTION_VIEW,Uri.parse(facebookUrl)));
}
 


编辑:这已经有一段时间,它看起来像FB://轮廓和FB://页不再支持。以下是我一直在生产中使用的方法:

  / **
 *意图打开官方的Facebook应用程序。如果未安装Facebook应用程序则
 *默认Web浏览器将采用与LT; / P&GT;
 *
 *用法示例:LT; / P&GT;
 *&LT; code取代; newFacebookIntent(co​​ntext.getPackageManager(),https://www.facebook.com/JRummyApps");</$c$c></p>
 *
 * @参数PM
 *在{@link PackageManager}的实例。
 * @参数的URL
 *完整的URL到Facebook页面或轮廓。
 返回:将打开Facebook页面/配置文件的意图。
 * /
公共静态意图newFacebookIntent(PackageManager时许,字符串URL){
    乌里URI;
    尝试 {
        pm.getPackageInfo(com.facebook.katana,0);
        // http://stackoverflow.com/a/24547437/1048340
        URI = Uri.parse(FB:// facewebmodal /˚FHREF =?+网址);
    }赶上(PackageManager.NameNotFoundException E){
        URI = Uri.parse(URL);
    }
    返回新意图(Intent.ACTION_VIEW,URI);
}
 

I used to open my facebook page from my app using the below code, but this does not work anymore starting facebook v11.0.0.11.23 released on June 21, 2014, any idea how to open the page in the new facebook app? To note that it opens now the facebook app but without opening the specified page, it used to work just fine before the latest update

public void openFacebookPage() {
    Intent intent = null;
    try {
        context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/<id here>"));
        //tried this also
        //intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<id here>"));
    } catch (Exception e) {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<name here>"));
    }
    context.startActivity(intent);
}

解决方案

In Facebook version 11.0.0.11.23 (3002850) fb://profile/ and fb://page/ are no longer supported. I decompiled the Facebook app and was able to come up with the following solution:

String facebookUrl = "https://www.facebook.com/JRummyApps";
try {
    int versionCode = getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
    if (versionCode >= 3002850) {
        Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
        startActivity(new Intent(Intent.ACTION_VIEW, uri));;
    } else {
        // open the Facebook app using the old method (fb://profile/id or fb://page/id)
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/336227679757310")));
    }
} catch (PackageManager.NameNotFoundException e) {
    // Facebook is not installed. Open the browser
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
}


Edit: It has been some time and it looks like fb://profile and fb://page are no longer supported. Below is the method I have been using in production:

/**
 * Intent to open the official Facebook app. If the Facebook app is not installed then the
 * default web browser will be used.</p>
 * 
 * Example usage:</p>
 * <code>newFacebookIntent(context.getPackageManager(), "https://www.facebook.com/JRummyApps");</code></p>
 * 
 * @param pm
 *            Instance of the {@link PackageManager}.
 * @param url
 *            The full URL to the Facebook page or profile.
 * @return An intent that will open the Facebook page/profile.
 */
public static Intent newFacebookIntent(PackageManager pm, String url) {
    Uri uri;
    try {
        pm.getPackageInfo("com.facebook.katana", 0);
        // http://stackoverflow.com/a/24547437/1048340
        uri = Uri.parse("fb://facewebmodal/f?href=" + url);
    } catch (PackageManager.NameNotFoundException e) {
        uri = Uri.parse(url);
    }
    return new Intent(Intent.ACTION_VIEW, uri);
}

这篇关于打开Facebook页面从Android应用程序(在Facebook的版本&GT; V11)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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