Monday, February 22, 2010

BlackBerry API - SMS - DatagramConnection.send() hangs/freezes

Problem:


public void SendSMS(String input){
try {
DatagramConnection dgConn;
dgConn = (DatagramConnection)Connector.open("sms://15195555555");
byte[] data = input.getBytes();
Datagram dg = dgConn.newDatagram(dgConn.getMaximumLength());
dg.setData(data, 0, data.length);
dgConn.send(dg); <------ hangs right here!!!! and no Throwable was ever thrown!!!
} catch (Throwable t) {
t.printStackTrace();
}
}


Solution:
Check the length of the message, in my case, it hangs when the message is >160 in length.