打开安卓手机上的Facebook用户个人资料

3

当我尝试通过官方Facebook应用程序打开Facebook个人资料时,出现错误:加载传记时出错,内容不可用。我尝试了许多代码,但没有什么效果。只有在设备上未安装Facebook应用程序时才能在浏览器中正常工作。

这是当前的代码:

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应用程序和浏览器之间进行选择,我很喜欢这个!因此,我的问题得到了解答 =D。


你的应用程序是否具有适当的权限? - Matt
无法做到这一点。 - WizKid
在Facebook的开发者页面还是AndroidManifest文件中?在AndroidManifest文件中,我已经有了所有适当的权限。 - WiKo.O
1个回答

5

我曾经遇到过类似的问题,发现当我尝试使用与您相同的方法时,只有在查看我的个人资料(或Facebook应用程序中当前登录的用户)时才有效,但每当我试图显示其他人的Facebook页面时,最终我找到了这个答案:

https://dev59.com/62445IYBdhLWcg3wia2V#24547437

长话短说,现在不再可能,目前唯一的解决办法是让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();

   }

它能够工作,但我将此行更改为: String url = "https://www.facebook.com/"+idFacebook; - Tiger developer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接