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
bbCanDev
Posts: 2
Registered: ‎09-10-2009
My Device: Not Specified
Accepted Solution

Error trying to send a sms message from my application

 I am trying to send a SMS message from my application. So i do the following to send a message 
     public boolean sendSMS(String link) {
         TextMessage text = null;
         try {
             MessageConnection conn = (MessageConnection) Connector.open("sms://");
             text = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
             text.setPayloadText(link);
         } catch (Exception e) {
             Logger.logException("Exception creating sms message: "+ e.toString(), e);
             return false;
         }
         if (link != null) {
             Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(text));
         } else {
             Logger.logMessage("Unable to send SMS at this time. Please try again later.");
             return false;
         }
         return true;
     }
     
 In the above code I create a MessageConnection by passing "sms://" since a MessageConnection cannot be created with a space. 
 After I execute the above code the control is navigated to RIM's SMS application. Here the user can add new one time recipient or add a number from his address book and send the SMS. 
 
 The problem is when the user sends the SMS, behinds the scene two SMS's messages are being tried to sent. One for the recipient added by the BB user and the other recipient with the TO number as "sms://" which was added by me to display RIM's SMS application. Eventually the recipient with "sms://" fails and sits in the users send SMS folder as failed. To the end user it seems like the message was not sent to the recipient which he just added from the address book. In reality the message does get sent successfully to the recipient which he just added from the address book and the failed message is the TO number with "sms://" which was added initially to display RIM's SMS application.  
 
 Is there a way I can open a SMS message with no recipient? The user can always add recipient in the RIM's SMS application.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Error trying to send a sms message from my application

I don't understand what you are using MessageConnection for. It's not needed here, I don't think.

 

If you are sending the SMS using RIM's Messages app, just create the Message object and pass it as an argument in the invoke statement.

 

 

Developer
sahil_khanna
Posts: 112
Registered: ‎07-19-2009
My Device: Not Specified

Re: Error trying to send a sms message from my application

Hi,

 

You're trying to techniques at the same time when only one is required. You'll have to use any of the following.

 

1. Create an application which uses the message connection to send sms as described below.

 

smsAddress = "9876543210";

smsText = "Sending SMS from my application";

//connect and send message

MessageConnection messageConnection = (MessageConnection) Connector.open("sms://" + smsAddress);

TextMessage sms = (TextMessage)messageConnection.newMessage(MessageConnection.TEXT_MESSAGE);

sms.setPayloadText(smsText);

messageConnection.send(sms); 

 

 

2. Invoke the native BlackBerry SMS application available in your device.

 

Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(text));

Retired
dconeybeare
Posts: 16
Registered: ‎01-12-2009
My Device: 9000

Re: Error trying to send a sms message from my application

Another option is to just create your own implementation of TextMessage and use that instead of opening an essentially-useless connection just to get an instance of TextMessage.  The TextMessage interface is very small and straight-forward, very easy to implement yourself.

 

 

public class MyTextMessage implements TextMessage {

private final Date _timestamp;
private String _payloadText;
private String _address;

public MyTextMessage() {
this._timestamp = new Date();
}

public String getAddress() {
return this._address;
}

public String getPayloadText() {
return this._payloadText;
}

public Date getTimestamp() {
return this._timestamp;
}

public void setAddress(String address) {
this._address = address;
}

public void setPayloadText(String payloadText) {
this._payloadText = payloadText;
}

}

 

 Then, to launch the message app for the user do something like this:

 

 

TextMessage textMessage = new MyTextMessage(); textMessage.setPayloadText("Hey, this is the message body"); textMessage.setAddress("sms://+15556667777"); MessageArguments args = new MessageArguments(textMessage); Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, args);

 

 

 

 

New Developer
bbCanDev
Posts: 2
Registered: ‎09-10-2009
My Device: Not Specified

Re: Error trying to send a sms message from my application

Thanks a lot dconeybeare your solution worked for me. Especially since i had no number to pass into this (MessageConnection) Connector.open(""); 

 

 

Developer
smiley
Posts: 1,523
Registered: ‎07-14-2008
My Device: Z10

Re: Error trying to send a sms message from my application

this does not work on OS5 :smileysad: