广播接收器为多部分短信 [英] BroadcastReceiver for multipart SMS
问题描述
我需要短信存储到一个SQLite数据库时,我收到一个。在这一刻它正常工作与SMS(160字),但如果我收到一个多短信是在大约155个字符截断的短信。
I need to store sms to a sqlite db when I receive one. At this moment it works fine with sms (160 chars), but if I receive a multipart sms it truncate the sms at about 155 chars.
这是我的code:
SmsBR.java
public class SmsBR extends BroadcastReceiver {
private DBManager dbm;
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[])bundle.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
}
if (messages.length > 0) {
dbm=DBManager.getDBM(null);
dbm.insertSMS(messages[0]);
}}}}
DBManager是一个单类,我写了简化读/写操作,我敢肯定,它与长文本没有问题!
DBManager is a singleton class that I wrote to simplify read/write operations and I'm sure that it has no problem with long texts!
推荐答案
按照多个应用程序,似乎多部分的SMS在同一意图接收,并且它们将重新由消息数组psented $ P $
according to several applications, it seems that multipart SMS are received in the same intent, and that they are represented by the messages array.
所以基本上,您检索完整的消息:
so basically, you retrieve the complete message:
StringBuffer content = new StringBuffer();
for (Message sms : messages) {
content.append(sms.getDisplayMessageBody());
}
String mySmsText = content.toString();
据我所知,似乎消息是正确的顺序。无论如何,我不知道有什么方法来检索邮件头(除解析PDU自己)。
As far as I know, it seems that the messages are in the correct order. Anyway, I don't know of any way to retrieve the message header (except parsing the pdu yourself).
这篇关于广播接收器为多部分短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!