简体   繁体   English

如果通过移动浏览器安装,则使用Facebook App打开粉丝页面

[英]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.

相关问题 如何通过浏览器重定向打开移动应用程序(例如 Facebook)? - How can I open a mobile app (eg Facebook) via a browser redirect? 使用javascript(无意图)打开移动应用(如果已安装) - Open mobile app (if installed) using javascript (without intent) 在移动浏览器中打开时,是否可以从 React 应用程序重定向到已安装的 Flutter 应用程序页面 - Is it Possible to redirect to installed flutter app page from react app when open in mobile browser 如何从移动浏览器启动应用程序(facebook / twitter / etc),但如果未安装应用程序,则回退到超链接 - How to launch apps (facebook/twitter/etc) from mobile browser but fall back to hyperlink if the app isn't installed 如果从我的网站在浏览器中安装了其他应用程序,如何在移动应用程序中打开共享对话框? - How to open share dialog in mobile app if installed else in browser from my website? 通过 facebook 移动应用内浏览器完成表单提交 - form submit done as get when via facebook mobile in-app browser 通过浏览器打开Android应用(如果已安装应用),否则打开playstore - Open Android app through browser if app is installed else open playstore 单击移动浏览器中的按钮后如何打开移动应用程序(使用javascript / react)[深度链接] - How to open mobile app after clicking a button in mobile browser (using javascript / react) [Deep Linking] 通过浏览器打开本机应用(非移动) - Open native app from browser (not mobile) 通过渐进式 web 应用在手机上打开相机 - Open camera on mobile via progressive web app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM