12-15-2009 04:34 AM
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 "operation prohibited bloacking operation on event despatcher 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:
12-15-2009 04:38 AM
tried with setting Message.setAddress()?
12-15-2009 01:06 PM
yes i have tried that tooo....
i feel its threading problem....
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.
12-16-2009 05:55 AM
Did you give a look into SMSdemo app shipped with JDE?
12-17-2009 02:52 AM
Yes i tried SMS sample provided with JDE
not working
)
even SMS is not getting send by that.......
but I am able to send SMS by using the inbuild messaging service......(the normal metthod to send SMS on any device)
12-17-2009 03:13 AM - edited 12-17-2009 03:16 AM
Which device, OS and carrier you are trying it on. If it is CDMA use DatagramConnection.
12-17-2009 04:25 AM
Details:
Device->9000 v406..0266 (platform 4.0.0.223).
CLDC 1.1.
MIDP 2.0.
Carrier-> IDEA(gsm).
12-17-2009 04:30 AM
Not a solution, just a suggestion have you tried with other network, cross check?
12-17-2009 04:48 AM
Thanks BBDeveloper,
I'll try that tooo.....