问题描述
这是我的Android应用程序,我想开一个链接到Facebook的个人资料在官方Facebook应用程序(如果已安装的应用程序,当然)。对于iPhone,存在着 FB://
URL方案,而是试图在Android设备上同样的事情会引发 ActivityNotFoundException
。
from my Android app, I would like to open a link to a Facebook profile in the official Facebook app (if the app is installed, of course). For iPhone, there exists the fb://
URL scheme, but trying the same thing on my Android device throws an ActivityNotFoundException
.
有机会在官方的Facebook应用程序从code。打开一个Facebook的个人资料?
Is there a chance to open a Facebook profile in the official Facebook app from code?
推荐答案
这适用于最新的版本:
- 到https://graph.facebook.com/<user_name_here> ( https://graph.facebook.com/fsintents 例如)
- 复制你的ID
-
使用此方法:
- Go to https://graph.facebook.com/<user_name_here> (https://graph.facebook.com/fsintents for instance)
- Copy your id
Use this method:
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>"));
}
}
如果用户已经安装它这将打开Facebook的应用程序。否则,将在浏览器中打开实
This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser.
这篇关于从Android应用程序打开的Facebook页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!