使用Facebook应用程序打开Facebook Url

Raj*_*A C 8 android intentfilter

我想从我的Android应用程序打开一个Facebook链接.该URL看起来像http://www.facebbok.com/abcxyz.它应该在Facebook应用程序中打开'abcxyz'页面,但它总是在浏览器中打开.

码:

try 
{
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    activityContext.startActivity(browserIntent);
} 
catch (ActivityNotFoundException ex) 
{
     ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

我的Android操作系统版本是6.0.1.

我在Instagram上遇到了同样的问题,http://www.instagram.com/abcxyz,而其他应用程序,比如Youtube.

小智 11

您应该使用Facebook的自定义网址方案强制应用程序打开您的页面,如下所示:

public Intent getFacebookIntent(String url) {

  PackageManager pm = context.getPackageManager();
  Uri uri = Uri.parse(url);

  try {
    ApplicationInfo applicationInfo = pm.getApplicationInfo("com.facebook.katana", 0);
    if (applicationInfo.enabled) {
      uri = Uri.parse("fb://facewebmodal/f?href=" + url);
    }
  }  

  catch (PackageManager.NameNotFoundException ignored) {
  }

  return new Intent(Intent.ACTION_VIEW, uri);
}
Run Code Online (Sandbox Code Playgroud)