【问题标题】:Send MMS programmatically以编程方式发送彩信
【发布时间】:2013-12-16 21:12:00
【问题描述】:

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

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

问题是它指向撰写消息页面,需要手动发送 SMS,我不希望在没有任何通知的情况下发送它应该发送我该怎么做??

有人请告诉我答案

【问题讨论】:

    标签: android mms


    【解决方案1】:

    我终于找到了一个 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));
    

    【讨论】:

    • 我得到这个 java.lang.IllegalArgumentException: Null 消息 URI。你能帮忙吗?
    • 什么是 Utils.hasICS()?
    • 还有什么是 APN_PROJECTION?
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      这样就可以直接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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-15
        • 1970-01-01
        • 2014-05-09
        • 2012-01-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多