11-27-2012 04:09 PM
Hi all,
I'm trying to receive and concatenate multi part SMS messages with my app - however, I'm having some issues accessing the header segments from the SMS messages.
_dc = (DatagramConnection) Connector.open("sms://0");
for (;;) {
if (_stop) {
return;
}
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
byte[] msgInfo = d.getData();
byte user_data_len = msgInfo[0];
byte user_data_header_len = msgInfo[1];
//handle message here
}
Solved! Go to Solution.
12-18-2012 11:06 AM - edited 12-18-2012 11:07 AM
DatagramConnection datagramConnection = (DatagramConnection) Connector.open("sms://");
DatagramBase datagram = (DatagramBase) datagramConnection.newDatagram(datagramConnection. getMaximumLength());
datagramConnection.receive(datagram); // blocking
int segCount = 1;
int segNumber = 1;
String messageID = null;
try
{
segCount = ((Integer) datagram.getProperty("sms-total-segments")).intVal ue();
segNumber = ((Integer) datagram.getProperty("sms-segment-number")).intVal ue();
messageID = ((Integer) datagram.getProperty("sms-ref-number")).toString() ;
}
catch (Exception e)
{
// this is not a concatenated SMS
}
String sender = datagram.getAddress();
String text = new String(datagram.getData());
Cheers
12-18-2012 07:18 PM
myraddin - lifesaver - thanks very much - works a dream!!
02-18-2013 01:43 AM
dear myraddin, i have been tried your code, it can be worked except the messageID, your code is below
messageID = ((Integer) datagram.getProperty("sms-ref-number")).toString()
I think that your meaning is "((String) datagram.getProperty.......", is it right?
However, i can not got messageID within Integer by using "sms-ref-number", please help to solve this problem, thank your very much!
02-18-2013 03:11 AM
02-18-2013 03:15 AM
02-18-2013 04:01 AM
Hi,
I tried to receive many multipart messages one by one, and the messageID were not null value, but zero.
I means that everytime I received the multipart messages, all of them would be the same one messageID, so I can not identify the different messages.
I also tried SMSPacketHeader.getID(), in the simulator, i got the ascending int value, but in device, i only got the max value of int type, 65535. I have no idear for this issue.![]()
02-25-2013 09:28 AM
I got it~![]()
thanks myraddin~
your code really workable, thanks again, have a good day!![]()