打开Facebook用户个人资料Android

时间:2015-01-02 17:25:04

标签: android facebook

当我尝试通过官方Facebook应用程序打开Facebook个人资料时出现此错误:加载传记时出错,内容不可用。 我尝试了许多代码,但没有。仅当设备上未安装Facebook App才能正常使用浏览器。 这是当前的代码:

try
 {
   Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/"+id_facebook));
                                                            startActivity(followIntent);
   final Handler handler = new Handler();
   handler.postDelayed(new Runnable()
   {
     @Override
     public void run() {
         Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/"+id_facebook));
         startActivity(followIntent);
     }
   }, 1000 * 2);
 }
catch (Exception e)
 {
   startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"+id_facebook)));
   String errorMessage = (e.getMessage()==null)?"Message is empty":e.getMessage();
   Log.e("Unlock_ScreenActivity:FacebookAppNotFound" ,errorMessage);
 }

更新

当我放弃并且我只放置https URI时,Android让我在Facebook APP和浏览器之间进行选择,我喜欢它!所以回答我的问题= D

1 个答案:

答案 0 :(得分:4)

我在当天遇到了类似的问题并发现当我尝试使用与您相同的方法时,只有在我想查看自己的个人资料(或Facebook应用中当前登录的用户)时才能使用它但每当我试图展示别人的Facebook页面时,我最终都会遇到这个答案:

https://stackoverflow.com/a/24547437/1879664

长话短说,它已经不再可能了,到目前为止唯一的解决办法就是让Facebook像你提到的那样加载facebook里面的网页,但不同之处在于如果用户无法在应用程序或已选择其他浏览器作为默认应用程序,您无法再通过Facebook打开该页面。使用此代码,您可以确保它将始终使用Facebook应用程序打开该页面(如果已安装)或将使用您的默认浏览器加载。这是我在我的应用中使用的代码:

try {

        mActivity.getPackageManager().getPackageInfo("com.facebook.katana", 0);
            String url = "https://www.facebook.com/profile.php?id=USER_ID"

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href="+url));
        }
        mActivity.startActivity(intent);

   } catch (Exception e) {

       Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/profile.php?id=USER_ID"));
       mActivity.startActivity(intent);

       e.printStackTrace();

   }