Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Facebook sdk's ShareContent in share intent android

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?

like image 364
Shafayat Mamun Avatar asked May 12 '16 11:05

Shafayat Mamun


1 Answers

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

share.setType("text/plain");
like image 146
Ryan Ford Avatar answered Oct 19 '22 18:10

Ryan Ford