HuyPV
Monday, February 14, 2011
File: SMSSender.java
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
/** Sends an SMS message */
public class SMSSender implements Runnable {
private String message;
private String phoneNumber;
public SMSSender() {
}
public void run() {
// 84 - Vietnam, 86 - China
// I am Vietnamese. My phone number is 097S292SB2 => +8497S292SB2
String address = "sms://+84" + phoneNumber;
MessageConnection smsconn = null;
try {
// Open the message connection.
smsconn = (MessageConnection) Connector.open(address);
// Create the message.
TextMessage txtmessage = (TextMessage) smsconn
.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setAddress(address);// !!
txtmessage.setPayloadText(message);
smsconn.send(txtmessage);
} catch (Exception e) {
e.printStackTrace();
}
if (smsconn != null) {
try {
smsconn.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
public void send(String message) {
this.message = message;
this.phoneNumber = "97529" + "25" + "82"; // test my phone number!
Thread t = new Thread(this);
t.start();
}
}
Title:
J2ME - Send SMS on your mobile
Description:
File: SMSSender.java import java.io.IOException; import javax.microedition.io.Connector; import javax.wireless.messaging.MessageConnect...
...
Rating:
4