gpt4 book ai didi

android - 从 android 应用程序打开 facebook 页面(在 facebook 版本 > v11 中)

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:53:31 24 4
gpt4 key购买 nike

我曾经使用以下代码从我的应用程序打开我的 facebook 页面,但是从 2014 年 6 月 21 日发布的 facebook v11.0.0.11.23 开始,这不再有效,知道如何在新的 facebook 应用程序中打开页面?要注意它现在打开 facebook 应用程序但没有打开指定的页面,它在最新更新之前工作得很好

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);
}

最佳答案

在 Facebook 版本 11.0.0.11.23 (3002850) 中,不再支持 fb://profile/和 fb://page/。我反编译了 Facebook 应用程序,并得出了以下解决方案:

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)));
}

编辑: 已经有一段时间了,似乎不再支持 fb://profile 和 fb://page。以下是我在生产中一直使用的方法:

/**
* 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);
}

关于android - 从 android 应用程序打开 facebook 页面(在 facebook 版本 > v11 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24526882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com