2016-09-15 83 views
0

如何从用户名打开Facebook个人资料?或者我应该在Android中使用哪个请求来获取(并打开)Facebook个人资料。Android:从用户名中打开Facebook应用程序中的个人资料

Intent intent; 

try { 
    activity.getPackageManager() 
      .getPackageInfo("com.facebook.katana", 0); // Checks if FB is even installed. 
    intent = new Intent(Intent.ACTION_VIEW, 
      Uri.parse("fb://profile/" + famous)); // Trys to make intent with FB's URI 
} catch (Exception e) { 
    intent = new Intent(Intent.ACTION_VIEW, 
      Uri.parse("https://www.facebook.com/" + famous)); // catches and opens a url to the desired page 
} 

activity.startActivity(intent); 

试过,但没有与用户名工作(去用户 - 这是在登录的用户 - 墙)和id(静态插入,显示错误 - 无法加载此配置文件)...

回答

1

您可以使用以下方法来打开,如fb://profile/fb://page/不再工作,但fb://facewebmodal/f?href=[YOUR_FACEBOOK_PAGE]可用于

public static Intent newFacebookIntent(PackageManager pm, String url) { 
    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); 
} 

url:完整的URL到Facebook页面或个人资料。

pmContext#getPackageManager()

相关问题