[英]Open a fanpage using Facebook App if installed via mobile browser
Is there any way to ask users to open a fanpage through their Facebook App if it is installed through using URL or Javascript? 是否有任何方法可以要求用户通过其Facebook App打开一个同人页面,如果它是通过使用URL或Javascript安装的?
After some data search, it seems that for IPhone, there are some "URL Scheme" (eg fb://page/{id}) ways to call and launch the installed Facebook App for specific actions, so will there be a similar way for Android too? 经过一些数据搜索后,对于iPhone,似乎有一些“ URL方案”(例如fb:// page / {id})方法可以调用并启动已安装的Facebook App进行特定操作,因此会有类似的方法也适用于Android?
This is a full fledged working code currently live in one of my apps: 这是我的其中一个应用程序中当前存在的完整的工作代码:
public static String FACEBOOK_URL = "https://www.facebook.com/YourPageName";
public static String FACEBOOK_PAGE_ID = "YourPageName";
//method to get the right URL to use in the intent
public String getFacebookPageURL(Context context) {
PackageManager packageManager = context.getPackageManager();
try {
int versionCode = packageManager.getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) { //newer versions of fb app
return "fb://facewebmodal/f?href=" + FACEBOOK_URL;
} else { //older versions of fb app
return "fb://page/" + FACEBOOK_PAGE_ID;
}
} catch (PackageManager.NameNotFoundException e) {
return FACEBOOK_URL; //normal web url
}
}
This method will return the correct url for app if installed or web url if app is not installed. 如果已安装,则此方法将返回适用于应用程序的正确URL;如果未安装,则将返回Web URL。
Then start an intent as follows: 然后按如下所示启动意图:
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getFacebookPageURL(this);
facebookIntent.setData(Uri.parse(facebookUrl));
startActivity(facebookIntent);
That's all you need. 这就是您所需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.