Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 72
Registered: ‎08-28-2008
My Device: Not Specified

SMS send issue with DatagramConnection???

[ Edited ]

Hi All,


i am trying to build a solution that sends sms from backround thread. i am using J2me WMA API to send sms . but WMA  API not works seamlessly in case of CDMA devices, there is a known issue with CDMA device i.e. attempt to send a Short Message Service (SMS) Text message programmatically using Wireless Messaging API (WMA) on a BlackBerry smartphone that operates on Code Division Multiple access (CDMA) networks, a java.io.IOException is encountered

 

find link below to the Knowledge base article

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/Known_I...

According to the doc, as a work around we can use DatagramConnection. But the problem is, when i sending sms with the datagram api, it sometime sends as a binary message. please note that binary message is received on non blackberry devices. sms send from blackberry to blackberry it looks fine.

byte[] completePayload = "Text message here".getBytes("UTF-8");
String phoneNo = "9871XXXXXX";
DatagramConnection smsConnection = (DatagramConnection)Connector.open("sms://"+phoneNo+":9876");
// tricky part - creating SmsAddress object
SmsAddress destinationAddr = new SmsAddress("//"+phoneNo+":9876");
SMSPacketHeader header = destinationAddr.getHeader();
// no need for the report
header.setStatusReportRequest(false);

header.setUserDataHeaderPresent(true);
// setting the validity and delivery periods
header.setValidityPeriod(SMSParameters.PERIOD_INDEFINITE);
header.setDeliveryPeriod(SMSParameters.PERIOD_INDEFINITE);

// allocating new datagram
Datagram d = smsConnection.newDatagram(completePayload.length);
// tricky part to set the destination, will not work without this call
((DatagramBase)d).setAddressBase(destinationAddr);

d.setData(completePayload, 0, completePayload.length);
//extractDatagarm(d,header);
// and finally sending it
smsConnection.send(d);

 


Anyone faced this problem before. Can anyone tell how i can solve this problem. is there any way to solve this by using UDH.

thanks in advance
 
Message Edited by vijaysaini on 02-24-2009 01:31 PM
Regards,
Vijay Saini.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 41
Registered: ‎08-05-2008
My Device: Not Specified

Re: SMS send issue with DatagramConnection???

Try using this code:

 

 

if(RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA){ DatagramConnection connection = null; try { byte[] bytes = msg.getBytes(); connection = (DatagramConnection) Connector.open( "sms://" + number ); System.err.println("connection opened"); Datagram datagram = connection.newDatagram( bytes, bytes.length ); connection.send( datagram ); } catch (IOException e) { System.err.println("Unable to send SMS "); throw e; } finally { connection.close(); connection=null; } }

 

 

 

New Developer
Posts: 72
Registered: ‎08-28-2008
My Device: Not Specified

Re: SMS send issue with DatagramConnection???

[ Edited ]

Hi,

 

With the above code, when I send sms message, sometime i gets the "IOException"  and sometime sms sends successfully without any exception. in case of sms message sends successfully, it looks like sms received as a Text message. but the issue with above code is when i send sms message with more that 160 char then i am always getting "IOException".

 

 

Please note, i am testing above code on 8820 in GSM network. i don't know whether or not IOException is encountered due to GSM netwok. let me know if IOException coming  due to GSM network, Any ways, i will try this code on CDMA device tomorrow.


 

Thanks in advance

 

Message Edited by vijaysaini on 02-24-2009 06:59 PM
Regards,
Vijay Saini.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 41
Registered: ‎08-05-2008
My Device: Not Specified

Re: SMS send issue with DatagramConnection???

You can use normal MessageConnection for sending on GSM handsets, this is good for CDMA.
New Developer
Posts: 72
Registered: ‎08-28-2008
My Device: Not Specified

Re: SMS send issue with DatagramConnection???

Hi All,

 

i am trying to send Concatenated SMS or segmented SMS or "long sms" with DatagramConnection with the help of below article. but i am getting IOException with code given in the article.

 

http://myhowto.org/java/j2me/22-sending-and-receiving-gsm-sms-on-blackberry-using-rim-apis/

 

Can anyone help me on this.

 

Thanks in advance
Regards,
Vijay Saini.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 41
Registered: ‎08-05-2008
My Device: Not Specified

Re: SMS send issue with DatagramConnection???

Hi,

 

If you want to send long sms using the datagram connection you would need to break sms into parts & set udh in every part of message. long sms is nothing but multiple sms messages with information about the length & segments in the udh.

You can read more about it & implement it.

ANother issue with long sms is if the receiving handset doesnt support long sms it wont display them. Also on CDMA networks UDH may be stripped out.

New Developer
Posts: 72
Registered: ‎08-28-2008
My Device: Not Specified

Re: SMS send issue with DatagramConnection???

Hi,

 

i had tried as you suggested but no luck. i am using below code to send longer sms

int dataCoding = SMSParameters.MESSAGE_CODING_8_BIT;

byte[] payload = message.getBytes();
int bytesPerSegment = SMSPacketHeader.getBitsPerSegment( dataCoding ) / SMSPacketHeader.getBitsPerCharacter( dataCoding ) ;
header.setStatusReportRequest(false);
header.setValidityPeriod(SMSParameters.PERIOD_INDEFINITE);
header.setDeliveryPeriod(SMSParameters.PERIOD_INDEFINITE);
header.setUserDataHeaderPresent(true);
header.setNumMessages(numMessages);

for(int index = 0 ; index < numMessages ; index++ )
{

myUDH = new byte[] {
0x05,
0x00,
0x03,
0x07,
Integer.valueOf( String.valueOf(numMessages), 16).byteValue() ,
Integer.valueOf( String.valueOf(index+1), 16).byteValue()
};



// some statements
System.arraycopy(myUDH, 0, completePayload, headerStart , myUDH.length);
System.arraycopy(payload, bytesPerSegment * index , completePayload, segmentDataStartIndex , segmentDataLen);

}

 

Could you please look the above code and let me know if i was doing something wrong. my main concern is about the UDH that i was using. is that correctly created.

 

if you have any code or refrence that help me. please share. 

 

Thanks in advance

Regards,
Vijay Saini.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
New Developer
Posts: 2
Registered: ‎05-06-2009
My Device: Not Specified

Re: SMS send issue with DatagramConnection???

I am in need of same thing.

I code is not working for me.

Did you get success in acheiving this task?

If yes, Then please share the code to send datagram packet with UDH.

 

Thanks

Krishna

New Developer
Posts: 2
Registered: ‎11-17-2009
My Device: Not Specified

Re: SMS send issue with DatagramConnection???

Hi,

In order to send sms messages with datagram connection one need to import these ->

import javax.microedition.io.Connector;
import javax.microedition.io.Datagram;
import javax.microedition.io.DatagramConnection;

 

To import these I use the library net_rim_api.jar. But when I add the library with net beans and import these then the jar file created by my code becomes huge like 5MB while my code is actually 66kb. So that I cant install the application to my phone.

 

Also I try to delete some files in the jar file to make the file smaller but then the application doesn’t work either. Is there a solution to send sms with datagram connection while the application doesn’t get bigger. Because it is ridiculus to have unused libraries in the application jar file.

Can anyone please help me!