Open Facebook page from Android app?

前端 未结 26 3104
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 07:03

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

26条回答
  •  抹茶落季
    2020-11-22 07:46

    Answering this in October 2018. The working code is the one using the pageID. I just tested it and it is functional.

    public static void openUrl(Context ctx, String url){
        Uri uri = Uri.parse(url);
        if (url.contains(("facebook"))){
            try {
                ApplicationInfo applicationInfo = ctx.getPackageManager().getApplicationInfo("com.facebook.katana", 0);
                if (applicationInfo.enabled) {
                    uri = Uri.parse("fb://page/");
                    openURI(ctx, uri);
                    return;
                }
            } catch (PackageManager.NameNotFoundException ignored) {
                openURI(ctx, uri);
                return;
            }
        }
    

提交回复
热议问题