Send MMS programmatically
Asked Answered
L

3

7

I want to send an MMS programmatically I used the following code for it

    Intent sendIntent1 = new Intent(Intent.ACTION_SEND); 
    try {

        sendIntent1.setType("text/x-vcard");
        sendIntent1.putExtra("address","0475223091");
        sendIntent1.putExtra("sms_body","hello..");
        sendIntent1.putExtra(Intent.EXTRA_STREAM,
                Uri.parse(vcfFile.toURL().toString()));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    startActivity(sendIntent1);

The problem is it directing to the compose message page and requires manually send the SMS and i dont want so without any notification it should send How can i do it??

SomeBody please share me the answer

Lili answered 13/5, 2013 at 9:9 Comment(0)
C
9

I finally found a solution that works 100%. Please refer to github project https://github.com/klinker41/android-smsmms. (Anyone who find it usefull please donate to author http://forum.xda-developers.com/showthread.php?t=2222703).

Notice, that obligatory settings are only

Settings sendSettings = new Settings();

sendSettings.setMmsc(mmsc);
sendSettings.setProxy(proxy);
sendSettings.setPort(port);

you can get them something like (found at Set APN programmatically on Android - answear by vincent091):

Cursor cursor = null;
if (Utils.hasICS()){
    cursor =SqliteWrapper.query(activity, activity.getContentResolver(), 
            Uri.withAppendedPath(Carriers.CONTENT_URI, "current"), APN_PROJECTION, null, null, null);
} else {
    cursor = activity.getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"),
        null, null, null, null);
}

cursor.moveToLast();
String type = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.TYPE));
String mmsc = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSC));
String proxy = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSPROXY));
String port = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSPORT));
Cyruscyst answered 16/12, 2013 at 12:47 Comment(3)
i get this java.lang.IllegalArgumentException: Null message URI. Can you help?Unveiling
what is Utils.hasICS()?Harvell
also what is APN_PROJECTION?Harvell
S
2

MMS is a HTTP based request in Android. You have to have mobile data to send an MMS. There are no APIs exposed by Android to send an MMS, as they have APIs for SMS. If you want your application to send MMS you will have to write everything. Please refer the AOSP code. https://github.com/android/platform_packages_apps_mms OR you can simply build the Intent and then launch the native Messaging App.

Surefire answered 23/9, 2013 at 16:36 Comment(0)
H
0

By this way you can mms directly, By giving the mobile No and Subject.And attach the image.

Uri uri = Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/test.png");
        Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra("address","1234567890");
        i.putExtra("sms_body","This is the text mms");
        i.putExtra(Intent.EXTRA_STREAM,"file:/"+uri);
        i.setType("image/png");
        startActivity(i);
Hamper answered 13/5, 2013 at 12:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.