5

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?

Tajmin
  • 353
  • 1
  • 7
  • 23
Shafayat Mamun
  • 439
  • 1
  • 6
  • 22
  • check this question, maybe it will help you http://stackoverflow.com/questions/35155890/android-share-custom-link-via-facebook – Wackaloon May 18 '16 at 09:54
  • That is only for facebook share. But I want to customize my share intent to use the desired facebook share from the intent. – Shafayat Mamun May 19 '16 at 05:46

2 Answers2

1

You need to add the Mime data type that the send intent is handling to get the appropriate activities returned:

share.setType("text/plain");
Ryan Ford
  • 326
  • 2
  • 9
0

Just try SharePhotoContent instead of ShareLinkContent. If you want using ShareLinkContent, please be sure that property.ImagePath pointed to real http image link. If link contain https check that is working in default android browser app.

Shadwork
  • 97
  • 4