0

how to open Facebook page link in Facebook App if installed , and if the app is not installed open in default browser in android ??

i tried this code but its not working ??

     Face.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = null;
            String Facebook = dbList.get(0).getFacebook().toString();
            try {
                // get the Twitter app if possible
                getPackageManager().getPackageInfo("com.facebook.android", 0);
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" +Facebook));
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            } catch (Exception e) {
                // no Twitter app, revert to browser
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/?hl=en"));
            }
            startActivity(intent);
        }
    });
Moayed Alayseh
  • 188
  • 3
  • 14

3 Answers3

1

check this link here

here more answer and this help you

click here Open Facebook page from Android app?

Community
  • 1
  • 1
Maulik Santoki
  • 532
  • 4
  • 14
0

Using this code you can open user profile

public static void opneFacebookProfile(Activity activity, String id) {
        Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
        String facebookUrl = getFacebookPageURL(activity, id);
        facebookIntent.setData(Uri.parse(facebookUrl));
        activity.startActivity(facebookIntent);
    }
Maulik Santoki
  • 532
  • 4
  • 14
0

I work with Unity Android games. The task is to open a Facebook Fan page in the FB app if it is installed. All I need to do is:

  1. Create Android Library and check if FB installed:

     public boolean isFbInstalled(Activity a) {
     PackageManager packageManager = a.getApplicationContext().getPackageManager();
     try {
         int versionCode = packageManager.getPackageInfo("com.facebook.katana",                  0).versionCode;
         if (versionCode >= 3002850) { //newer versions of fb app, no need to handle older
             return true;
         }
     } catch (PackageManager.NameNotFoundException e) {
         return false;
     }
    
     return false;
    

    }

  2. Go to this service and use generated links for different platforms :)