How to share text on facebook without having the application installed on Android?

0

I need to share a text and an image on facebook. On the net there are many tutorials that need to have the facebook app installed. Does anyone have any tutorial on how to do this without having facebook on Android? Thank you in advance.

    
asked by anonymous 10.03.2017 / 15:58

1 answer

0

This code snippet shares on facebook without necessarily having the app installed, it checks to see if it has the app, if it does not share it, but in this case it is sharing a link, I hope the validations that check if the app has you help!

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, urlToShare);
// See if official Facebook app is found
boolean facebookAppFound = false;
List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo info : matches) {
     if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook")){
          intent.setPackage(info.activityInfo.packageName);
          facebookAppFound = true;
          break;  
     }
}
// As fallback, launch sharer.php in a browser
if (!facebookAppFound) {
     String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" +              urlToShare;
     intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
startActivity(intent);

Source: share without facebook app installed

    
10.03.2017 / 16:52