I am trying to use the shareintent in my app but I ran into a problem when sharing a link to facebook, no images is shown with the preview. So tried customizing the android shareintent so that it uses the share functionality from facebooksdk when facebook is selected but I can't seem to get it working. Below is the code that I tried for customizing the 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 activitylist only consists of a single element. So how can I resolve this issue?
You need to add the Mime data type that the send intent is handling to get the appropriate activities returned:
share.setType("text/plain");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With