且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

非英语短信显示为多个字符串?

更新时间:2023-11-28 22:37:58


  

...但是当古吉拉特语被分成了多个字符串


块引用>

当一个短信超过了最大消息长度(这取决于你所使用的字符集),它可以被分解成几部分,并派出一个多部分消息。那是什么发生在你的情况,你已经结构化的code的方式,它看起来像您收到几个不同的文本。下面code是如何获得完整的邮件,以及始发号和时间戳的例子。

 最终目标[] = pdusObj(对象[])bundle.get(的PDU);
如果(pdusObj.length == 0)
    返回;SmsMessage味精= NULL;
StringBuilder的身体=新的StringBuilder();的for(int i = 0; I< pdusObj.length;我++){
    味精= SmsMessage.createFromPdu((字节[])pdusObj [I]);
    body.append(msg.getDisplayMessageBody()的toString());
}字符串报告+ msg.getDisplayOriginatingAddress =从短信()
                +:+ body.toString();长smsReceiveTime = msg.getTimestampMillis();

I am reading text messages in my application. Whenever an SMS arrives it comes to the app and is displayed.

It is working for English but when in the Gujarati language they're broken into more than one string.

Here's my code:

final Object[] pdusObj = (Object[]) bundle.get("pdus");
                msgs = new SmsMessage[pdusObj.length];
                for (int i=0; i<msgs.length; i++) {
                    msgs[i] = SmsMessage.createFromPdu((byte[])pdusObj[i]);
                    smsReceiveTime = msgs[i].getTimestampMillis();
                    str += "SMS from " + msgs[i].getDisplayOriginatingAddress();
                    str += " :";
                    str += msgs[i].getDisplayMessageBody().toString();
                    str += "\n";
                }

...but when gujarati has been broken into more than one string

When a text message exceeds the maximum message length (which depends on the character set you're using), it can be broken up into parts, and sent as a multipart message. That's what's happening in your case, and the way you've structured your code, it appears like you're receiving several different texts. The following code is an example of how to get the full message, as well as the originating number and timestamp.

final Object[] pdusObj = (Object[]) bundle.get("pdus");
if (pdusObj.length == 0)
    return;

SmsMessage msg = null;
StringBuilder body = new StringBuilder();

for (int i=0; i < pdusObj.length; i++) {
    msg = SmsMessage.createFromPdu((byte[])pdusObj[i]);
    body.append(msg.getDisplayMessageBody().toString());
}

String report = "SMS from " + msg.getDisplayOriginatingAddress()
                + " : " + body.toString();

long smsReceiveTime = msg.getTimestampMillis();