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

Asked

Viewed 85 times

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? Thanks in advance.

1 answer

0

This snippet of code shares on facebook without necessarily having the app installed, it checks if you have the app, if you don’t have it share, but in this case it’s sharing a Link, I hope the validations that check if you have the app help you!

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.