Am 22.02.2012 11:26, schrieb chavo:
hi,
could someone please provide me with a sample code for sending an sms
from a j2me app to smslib.thanks a lot.
Here is how I do it, just throw away all code which is not relevant for you
Marcel
/**
* Send a SMS from J2ME
* @author Marcel Ruff
*/
public class SmsSender implements Runnable {
private I_GuiNotification gui;
private String message;
private String phoneNumber;
private String smsPort;
private MessageConnection smsconn;
private String address;
private boolean send;
/**
* @param phoneNumber "+4577126236"
* @param smsPort If not "0" the SMS port is set
* @param message The content to send
* @param gui If not null it is used for showing msgBox about success/error
*/
public SmsSender(String phoneNumber, String smsPort, String message,
I_GuiNotification gui) {
this.phoneNumber = phoneNumber;
this.message = message;
this.smsPort = smsPort;
this.gui = gui;
}
/**
* Sends the message in a separate thread.
*/
public void sendMsg() {
if (this.smsPort == null || this.smsPort.length() < 1 || "0".equals(this.smsPort) ||
"-1".equals(this.smsPort))
this.address = "sms://" + this.phoneNumber;
else
this.address = "sms://" + this.phoneNumber + ":" + this.smsPort;
new Thread(this).start();
}
public void run() {
try {
smsconn = (MessageConnection) Connector.open(this.address);
} catch (Throwable e) {
e.printStackTrace();
if (this.gui != null) this.gui.msgBox("SMS failed", this.address + ": " + e.toString(),
AlertType.ERROR, 30000);
return;
}
try {
TextMessage msg = (TextMessage)
smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(this.message);
smsconn.send(msg);
} catch (Throwable e) {
e.printStackTrace();
if (this.gui != null) this.gui.msgBox("SMS failed", this.address + " '" + this.message
+ "': "
+ e.toString(), AlertType.ERROR, 30000);
return;
}
this.send = true;
if (this.gui != null) this.gui.msgBox("SMS success", this.address + " '" + this.message +
"'", AlertType.INFO, 3000);
}
public boolean isSend() {
return send;
}
}
--
You received this message because you are subscribed to the Google Groups "SMSLib
Discussion Group" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/smslib?hl=en.