Use Facebook sdk ShareContent in Android sharing app

I am trying to use shareintent in my application, but I had a problem while sharing the facebook link, the preview images are not displayed. So I tried setting up android android to use the share functions from facebookdk when the facebook function is selected, but I can't get it to work. Below is the code I tried to set up shareintent,

Intent share = new Intent(android.content.Intent.ACTION_SEND); PackageManager pm = getPackageManager(); List<ResolveInfo> activityList = pm.queryIntentActivities(share, 0); for (final ResolveInfo app : activityList) { if (app.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana")) { ShareLinkContent content = new ShareLinkContent.Builder() .setContentTitle(property.PropertyName) .setImageUrl(Uri.parse(property.ImagePath)) .setContentUrl(Uri.parse(property.PropertyPermaLink)) .build(); ShareDialog shareDialog = new ShareDialog(this); shareDialog.canShow(content); break; } else { share.setType("text/plain"); share.addFlags(share.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); share.putExtra(Intent.EXTRA_SUBJECT, ""); share.putExtra(Intent.EXTRA_TEXT, property.PropertyPermaLink); startActivity(Intent.createChooser(share, "Share property!")); } } 

After debugging the above code, I found that the activity list consists of only one element. So how can I solve this problem?

+7
android android-intent
source share
2 answers

You need to add a Mime data type that handles the sending intent in order to get the appropriate action:

 share.setType("text/plain"); 
+1
source share

Just try SharePhotoContent instead of ShareLinkContent. If you want to use ShareLinkContent, make sure that property.ImagePath points to a real link to the http image. If the link contains https verification, which works in the default browser application by default.

0
source share

All Articles