I am implementing share in my app. Sharing mixed content like image+text is possible with some apps like whatsapp, twitter etc. while facebook, linkedin etc. only allow content of one type(either image or text). How can this be achieved? E.g when whatsapp is selected it should send both, whereas when facebook is selected it should share text. One solution I thought of querying all the activities that can perform this action, then creating target intent. Below is what I have tried so far
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
shareIntent.putExtra(Intent.EXTRA_TEXT, title + "\n" + message);
List<ResolveInfo> resolveInfos = activity.getApplicationContext().getPackageManager().queryIntentActivities(shareIntent, PackageManager.MATCH_DEFAULT_ONLY);
ArrayList<Intent> mainIntentList = new ArrayList();
Iterator<ResolveInfo> it = resolveInfos.iterator();
while (it.hasNext()) {
ResolveInfo localResolveInfo = it.next();
String str = localResolveInfo.activityInfo.packageName;
if (imageSupportingApps.contains(str) && (imageUri != null)) {
Intent localIntent = new Intent(Intent.ACTION_SEND);
localIntent.setComponent(new ComponentName(str, localResolveInfo.activityInfo.name));
localIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
localIntent.setType("image/*");
localIntent.putExtra(Intent.EXTRA_SUBJECT, title);
localIntent.putExtra(Intent.EXTRA_TEXT, title + "\n" + message);
localIntent.setPackage(str);
mainIntentList.add(localIntent);
}
}
Intent in = Intent.createChooser(shareIntent, "Share on ..");
in.putExtra(Intent.EXTRA_INITIAL_INTENTS, mainIntentList.toArray(new Parcelable[localArrayList1.size()]));
activity.startActivity(in);
Update 1: This is what I tried so far. But it is only sending text. It is not sharing image with whatsapp.