Search code examples
javaandroidandroid-intentmmsandroid-mms

Send mms in background service without showing any interface


The below code is navigating me too default MMS app with the photo, text and number

Intent mmsIntent = new Intent(Intent.ACTION_SEND);
mmsIntent.putExtra("sms_body", "text");
mmsIntent.putExtra("address", "121");
mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "photo.jpeg")));
mmsIntent.setType("image/jpeg");
mmsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(mmsIntent);

What I need is to send mms in background without showing any kind of interface. I can send text sms using SmsManager using

SmsManagaer smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(num, null, "Help Me", null, null);

Can I use smsManager.sendMultimediaMessage() to send mms(I'd tried this method and no success yet)? If not then what it's use? And is there any other way to send mms in background?


Solution

  • What you are doing is creating Implicit Intent which will launch another application depending upon the action you are sending. It may show Chooser dialog if there are more than one applications installed with the action registered in the intent filter.

    To send a MMS without user interaction you can use smsManager.sendMultimediaMessage() to send MMS but this method was introduced since API version 21. You can refer the demo over here to see how to send MMS using sendMultimediaMessage().

    To support versions prior to that you can integrate the solution listed in this answer.