Open Facebook page from Android app?

前端 未结 26 3609
被撕碎了的回忆
被撕碎了的回忆 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:44

    My answer builds on top of the widely-accepted answer from joaomgcd. If the user has Facebook installed but disabled (for example by using App Quarantine), this method will not work. The intent for the Twitter app will be selected but it will not be able to process it as it is disabled.

    Instead of:

    context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
    return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/620681997952698"));
    

    You can use the following to decide what to do:

    PackageInfo info = context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
    if(info.applicationInfo.enabled)
        return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/620681997952698"));
    else
        return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/620681997952698"));
    

提交回复
热议问题