I have tried the following but none of them are reaching my goal.
following code showing a chooser.
Intent mmsIntent = new Intent(Intent.ACTION_SEND);
mmsIntent.putExtra("sms_body", "some text");
mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
mmsIntent.setType("image/png");
startActivity(mmsIntent);
following code shows compose message view, but image is not attached.
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));//Uri.parse(url));
smsIntent.setData(Uri.parse("sms:" + "89565656"));
startActivity(smsIntent);
But, I need the message compose view with my image from sd card. How to achieve this.
Thank you in advance...!
Try this
Intent mmsIntent = new Intent(Intent.ACTION_SEND);
//file is the file on the SD Card
mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file.toURL().toString()));
mmsIntent.setType("image/png");//mmsIntent.setType("image/*"); Maybe?
startActivity(mmsIntent);
Try this code if don't want to open chooser and directly attach image
PackageManager pm = getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
for (int i = 0; i < resInfo.size(); i++) {
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if(packageName.contains("mms")) {
Log.d("TAG", packageName + " : " + ri.activityInfo.name);
sendIntent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
}
}
sendIntent.putExtra("address", "1234567890");
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("/sdcard/DCIM/Camera/image.jpg"));
sendIntent.setType("image/*");
startActivity(sendIntent);
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