I have some images in my drawable folder, and also an int array of those images. Now I am trying to send email via gmail with an attached image from my drawable folder, everything is working fine in android 2.3 but in android 4.0 the extension of image is missing. I didn't find any solution. Below is the code I used.
Uri imageuri = Uri.parse("android.resource://MyPackageName/" + SplashActivity.mBitmap_mixed_images[int_image_position]);
Intent intent = new Intent(Intent.ACTION_SEND);
if(imageuri != null){
intent.putExtra(Intent.EXTRA_STREAM, imageuri);
intent.putExtra(Intent.EXTRA_SUBJECT, "150+ Reasons to Quit Smoking");
//intent.putExtra(Intent.EXTRA_TEXT, "www.selftalk.info");
intent.setType("image/html");
}else{
intent.setType("plain/text");
}
final PackageManager pm = getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm") ||
info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
if (best != null)
intent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
startActivity(intent);