【问题标题】:Sending full length SMS using Android使用 Android 发送完整长度的 SMS
【发布时间】:2014-07-07 14:49:04
【问题描述】:

我正在尝试使用我的应用程序发送 SMS 消息。

但是,通过我的应用程序发送消息时,我的消息在 67 个字符后被截断。我知道 SMS 的最大长度为 160 个字符,并且可以使用原生 Android 消息应用程序发送此长度的消息。

这是我的代码:

String textToSend = "this is a string that is about 100 characters or so. It is being split up by android after 67 characters.";

SmsManager sms = SmsManager.getDefault();
ArrayList<String> msgStringArray = sms.divideMessage(textToSend);

for(String s : msgStringArray){
    //this will say 67 and then the remainder 
    Log.d(TAG, "STRING LENGTH: " + s.length() + " " + s);
}

sms.sendMultipartTextMessage(selectedNumber, null, msgStringArray, null, null);

我认为这可能是编码或类似的东西。我认为默认情况下使用 16 位编码而不是 GSM,但我无法找到任何解决此问题的示例。一个代码示例会很棒!

我在 S3 上使用 android 4.4 来测试这个。

谢谢!

【问题讨论】:

标签: java android mobile sms


【解决方案1】:

我想通了。我的预感是 unicode 编码是正确的。

无论如何,我偶然发现了这个网站:http://www.wrankl.de/JavaPC/SMSTools.html

有一个叫做 convertUnicode2GSM 的方法,我用它来转换我的字符串。现在它在一条短信中发送整个消息,而不是在 67 个字符后中断。

【讨论】:

  • 链接失效了,能把方法放在这里吗?
【解决方案2】:
String smsNumber = "Insert number here"; //AIMS HELPLINE
String smsText = "Need to book an appointment with your hospital";
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsText);
startActivity(intent);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    相关资源
    最近更新 更多