How to attach image in MMS programmatically in android

I tried the following, but not one of them reaches my goal.

The following code showing the selector.

 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);

The following code shows a message message, but the image is not connected.

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 to make up a view with my image from the SD card. How to achieve this.

Thanks in advance...!

+3
source share
2 answers

try it

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);
+3
source

Try this code if you do not want to open the selection program and attach the image directly

    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);
+1
source

All Articles