以编程方式发送彩信

时间:2013-05-13 09:09:24

标签: android mms

我想以编程方式发送彩信我使用了以下代码

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

问题是它指向撰写邮件页面并需要手动发送短信,我不想这样,没有任何通知它应该发送我怎么能这样做?

SomeBody请与我分享答案

3 个答案:

答案 0 :(得分:9)

我终于找到了100%有效的解决方案。请参阅github项目https://github.com/klinker41/android-smsmms。 (任何发现它有用的人请捐赠给作者http://forum.xda-developers.com/showthread.php?t=2222703)。

请注意,强制性设置仅为

Settings sendSettings = new Settings();

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

你可以得到类似的东西(在Set APN programmatically on Android找到 - 由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));

答案 1 :(得分:2)

MMS是Android中基于HTTP的请求。 您必须拥有移动数据才能发送彩信。 Android没有公开发送MMS的API,因为它们有用于SMS的API。 如果您希望您的应用程序发送彩信,您将必须编写所有内容。 请参阅AOSP代码。 https://github.com/android/platform_packages_apps_mms 或者您可以简单地构建Intent,然后启动本机Messaging App。

答案 2 :(得分:0)

通过这种方式你可以直接mms,给手机号码和主题。并附上图像。

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);
相关问题