1

I'm coding an android - java app which can open a Facebook post url (ex: https://www.facebook.com/BaHangXom.0/videos/2377836809193490). I tried some ways to start Facebook app with intent but unsuccessfully.

    Intent intent =  new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=" + "https://www.facebook.com/BaHangXom.0/videos/2377836809193490"));
    intent.setPackage("com.facebook.katana");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

Could you please give me any idea? Thank you so much.

Daan Seuntjens
  • 880
  • 1
  • 18
  • 37
phong dep trai
  • 123
  • 1
  • 9

2 Answers2

1

Simply open the url:

Intent intent =  new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/BaHangXom.0/videos/2377836809193490"));
startActivity(intent);

This is the most simple and universal way: user will be able to choose (and remember the choice) whether they want to open the link via main Facebook app, Facebook lite, or the browser.

Alex Timonin
  • 1,872
  • 18
  • 31
0

You can open the facebook app using this code:

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) {
      // http://stackoverflow.com/a/24547437/1048340
      uri = Uri.parse("fb://facewebmodal/f?href=" + url);
    }
  } catch (PackageManager.NameNotFoundException ignored) {
  }
  return new Intent(Intent.ACTION_VIEW, uri);
}
Daan Seuntjens
  • 880
  • 1
  • 18
  • 37