Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

android - Send MMS programmatically

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...