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 Contributor
Posts: 3
Registered: ‎07-13-2012
My Device: Curve 8520
My Carrier: Claro

IllegalArgumentException when sending SMS to a specific number

[ Edited ]

Hello, I've just develop a method that allows me to send SMS. It works as expected with most of the phone numbers I tried, but what I need is that this method send the SMS to a number that starts with an asterisk (*), something like *1111. When I set the address to the Connector or the TextMessage object, throws an Illegal Argument Exception.

 

The method is basically is:

 

String msg = "Hello";
String number = "*1111";

try {
	MessageConnection _dc = null;
	_dc = (MessageConnection)Connector.open("sms://:0");
	TextMessage text = (TextMessage) _dc.newMessage(MessageConnection.TEXT_MESSAGE);
	
	text.setAddress("sms://" + number); //Line with problem
	text.setPayloadText(msg);
	_dc.send(text);
	_dc.close();
} catch ( Exception e) {
	Dialog.inform(R.getString(R.strErrorSendMessage) + "\n" + 
			e.getClass().getName() + ": " + e.getMessage());
}

 

I also tried other method to send the SMS, this method look like:

 

final String _openString = "sms://";
String msg = "Hello";
String number = "*1111";

try {
    DatagramConnection _dc = null;
    _dc = (DatagramConnection)Connector.open(_openString + number); // Line with problem
    byte[] data = msg.getBytes();
    Datagram d = _dc.newDatagram(_dc.getMaximumLength());
    d.setData(data, 0, data.length);
    _dc.send(d);
} catch ( Exception e) {
    Dialog.inform(R.getString(R.strErrorSendMessage));
}

 

Thanks for the help.

 

EDIT: I'm supporting since OS 5.

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: IllegalArgumentException when sending SMS to a specific number

welcome to the support forums.

please check the detail message of the exception.
i am not sure if there is an issue with a number like this, so you should check all information the system gives you.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Contributor
Posts: 3
Registered: ‎07-13-2012
My Device: Curve 8520
My Carrier: Claro

Re: IllegalArgumentException when sending SMS to a specific number

The message of the exception only have the number that I'm sending to it (i.e. '*1111').

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: IllegalArgumentException when sending SMS to a specific number

So are you saying the number you are trying to send this to has the number "*11111".  What does the "*" at the start mean?

 

Can you tell us the full exception message, i.e. the text you get from:

 

R.getString(R.strErrorSendMessage) + "\n" + e.getClass().getName() + ": " + e.getMessage()

 

BTW, you should not be doing this on the Event Thread.  I am surprised you are not getting an IllegalStateException.  But I think we can leave this issue till we have resolved the illegalArgumentException. 

New Contributor
Posts: 3
Registered: ‎07-13-2012
My Device: Curve 8520
My Carrier: Claro

Re: IllegalArgumentException when sending SMS to a specific number

[ Edited ]

"*" is part of the phone number, it tells the carrier that the number is a short number mapped to other number (or pull of phone numbers, I can't tell for sure). 

 

I know how to extract the exception message, that's how I extract it. It only contains "*11111", and that doesn't tell me anything.

 

And I'm not doing this in the Event Thread, the code above is executed in another thread, within the run method; neither I using only Dialog.inform (It's just a simplification).

 

EDIT: I debugged the app in another device and this time it has a message. In the first method the message is "invalid destination address: trailing characters: *11111". And in the second method is "invalid URL: trailing characters: *11111". 

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: IllegalArgumentException when sending SMS to a specific number

Sorry, I think you will have to replace the coded number with the 'real' number in order to get this to work.