WiKo.O
WiKo.O

Reputation: 31

Open Facebook User Profile Android

When I try to open a Facebook Profile through the official Facebook App i have this error: error loading the biography, the content is not available. I tried with many codes but nothing. Only if Facebook App is not installed on the device work right with the browser. Here is the current code:

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);
 }

UPDATE:

When I give up and i only put the https URI, Android let me choose between Facebook APP and the browser, and i like it! So my question is answered =D

Upvotes: 3

Views: 1677

Answers (1)

Alan Poggetti
Alan Poggetti

Reputation: 566

I ran into a similar problem back in the day and found out that when I tried to use the same method as you it only worked if I wanted to view my own profile (or the current logged in user in the Facebook app) but whenever I tried to show someone else's facebook page so I eventually came across this answer:

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

Long story short, it's no longer possible and the only workaround so far is to make facebook load the web page inside facebook just like you've mentioned but the difference is that without forcing it, if the user can't choose between apps or has already selected another browser as a default app you can no longer open that page through facebook. With this code you can ensure that it will always open that page with the facebook app if it's installed or it would load with your default browser. Here's the code that I use in my apps:

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();

   }

Upvotes: 5

Related Questions