BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-15-2009, 10:49 PM   #1 (permalink)
New Member
 
Join Date: Dec 2009
Model: 9000
PIN: N/A
Carrier: Airtel
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question Unable to send SMS through custom SMS application.

Please Login to Remove!

Hi I am trying to developed a custom SMS application. I got some code snippet from other posts but I am still facing problem implementing the code. I tried two methods:



Method 1:


public class EnterNumber extends MainScreen {
LabelField titleEnterNumber = new LabelField("Enter Number",LabelField.ELLIPSIS);
HorizontalFieldManager hfm2 = new HorizontalFieldManager();
HorizontalFieldManager hfm3 = new HorizontalFieldManager();
BasicEditField msgno = new BasicEditField("Enter No:",null,10,TextField.PHONENUMBER);

public EnterNumber(){

setTitle(titleEnterNumber);


hfm2.add(msgno);


add(new SeparatorField());
add(hfm2);

}
protected void makeMenu(Menu menu, int instance){
menu.add(sendSms);
}


private MenuItem sendSms = new MenuItem("Send",110,10){
public void run(){
sendSMS();
}
};

public void sendSMS(){
Dialog.alert("inside sms");
String address = "sms://"+msgno.getText();
Dialog.alert(address);
System.out.println(address);

MessageConnection smsconn = null;

try {
smsconn = (MessageConnection) Connector.open(address);

TextMessage txtmessage = (TextMessage) smsconn.newMessage(MessageConnection.TEXT_MESSAGE) ;
txtmessage.setPayloadText("SMS sending suceessfull");
Dialog.alert("Messge is loaded");
System.out.println("Messge is loaded");
smsconn.send(txtmessage);
Dialog.alert("Message sent");
System.out.println("Message sent");
} catch (Exception t) {
System.out.println(t.getMessage());
Dialog.alert(t.getMessage());
System.out.println(t.getClass().getName());
}

if (smsconn != null) {
try {
smsconn.close();
} catch (IOException ioe) {
System.out.println(ioe.getMessage()); }
}

}
}



Using this I get an error alert after setPayloadText(): saying "blocking operation prohibited on event dispatcher thread".



So I used the Method 2 trying to run it in a thread:



public class EnterNumber extends MainScreen implements Runnable{
LabelField titleEnterNumber = new LabelField("Enter Number",LabelField.ELLIPSIS);
HorizontalFieldManager hfm2 = new HorizontalFieldManager();
HorizontalFieldManager hfm3 = new HorizontalFieldManager();
BasicEditField msgno = new BasicEditField("Enter No:",null,10,TextField.PHONENUMBER);
Thread t;
public EnterNumber(){
t = new Thread(this);
setTitle(titleEnterNumber);


hfm2.add(msgno);


add(new SeparatorField());
add(hfm2);

}
protected void makeMenu(Menu menu, int instance){
menu.add(sendSms);
}


private MenuItem sendSms = new MenuItem("Send",110,10){
public void run(){
Dialog.alert("inside run");
t.start();
}
};

public void run(){
Dialog.alert("inside sms");
String address = "sms://"+msgno.getText();
Dialog.alert(address);
System.out.println(address);

MessageConnection smsconn = null;

try {
smsconn = (MessageConnection) Connector.open(address);

TextMessage txtmessage = (TextMessage) smsconn.newMessage(MessageConnection.TEXT_MESSAGE) ;
txtmessage.setPayloadText("SMS sending suceessfull");
Dialog.alert("Messge is loaded");
System.out.println("Messge is loaded");
smsconn.send(txtmessage);
Dialog.alert("Message sent");
System.out.println("Message sent");
} catch (Exception t) {
System.out.println(t.getMessage());
Dialog.alert(t.getMessage());
System.out.println(t.getClass().getName());
}

if (smsconn != null) {
try {
smsconn.close();
} catch (IOException ioe) {
System.out.println(ioe.getMessage()); }
}

}
}



I only get one alert: "Inside run". After that no sms is sent, no error, no alert, no exception please help.



I am using following things for developing the application:



1. I am testing on BB 9000 handsets.
2. Using blackberry 4.6 plugin for Eclipse.
3. Error I am getting: Already mentioned with code.
4. Code: Already given both the implementation techniques.


METHOD 3:


I later tried a new approach trying to launch a new thread in constructor of a new class and tried to send SMS through that but the result was same as METHOD 2.
Offline  
Old 12-16-2009, 08:21 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

Are you aware that you cannot access the UI from a worker thread? These "Dialog.alert" calls are worthless in this context.
Offline  
Old 12-16-2009, 01:42 PM   #3 (permalink)
New Member
 
Join Date: Dec 2009
Model: 9000
PIN: N/A
Carrier: Airtel
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, thanks for the advice.......


but if i remove that can i send the sms?
Offline  
Old 12-16-2009, 06:05 PM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

Not sure what is wrong with the SMS code - I'm just pointing out that you dialogs won't show up.

Ideas:

1. you have several different operations in your try/catch block. Break this up a little.

2. Have you checked the event log on th device? YOu may have an exception there

3. Are permissions set to allow SMS access?

Last edited by Dougsg38p : 12-16-2009 at 06:12 PM.
Offline  
Old 12-17-2009, 02:59 AM   #5 (permalink)
New Member
 
Join Date: Dec 2009
Model: 9000
PIN: N/A
Carrier: Airtel
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation @Dougsg38p

HI Dougsg38p,

Thanks again.

I am trying many things at my end. If I get result I will suerly upload the solution!

When I run the app on device it asks me for allowing to send SMS i select allow everytime......

it shows some activity icon in "top-right corner" and then nothing happens.

While is I use the default messaging application, message is send without any problems.

Last edited by antas.mishra : 12-17-2009 at 03:01 AM.
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.