/************************************************** ***
J2ME SMS
Sending SMS in J2ME
insert this line into JAD file:
Port-SMS: 50056
************************************************** ****/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.wireless.messaging.*;
import javax.microedition.io.*;
import java.io.*;
public class SendSMSextends MIDlet
implements CommandListener, Runnable {
private Display display;
private Command cmdExit, cmdContinue, cmdBack, cmdSend;
private Displayable prevScreen;
private TextBox tfNum, tfText;
private String port;
private Thread thread;
private Alert alert;
private final String INVALID_PHONE =
"Nomor yang dimasukkan tidak absah";
public SendSMS() {
display = Display.getDisplay(this);
port = "50056";
if(getAppProperty("Port-SMS") != null)
port = getAppProperty("Port-SMS");
cmdExit = new Command("Exit", Command.EXIT, 1);
cmdContinue = new Command("Continue", Command.SCREEN, 1);
cmdBack = new Command("Back", Command.BACK, 1);
cmdSend = new Command("Send", Command.SCREEN, 1);
alert = new Alert(null);
alert.setTimeout(3000);
}
public void startApp() {
tfNum = generatePhoneInput();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == cmdExit) {
destroyApp(false);
notifyDestroyed();
} else if (c == cmdBack) {
display.setCurrent(tfNum);
} else if (c == cmdContinue) {
if (!isValidPhoneNumber(tfNum.getString())) {
alert.setType(AlertType.ERROR);
alert.setString(INVALID_PHONE);
display.setCurrent(alert,tfNum);
} else {
tfText = generateMessageInput();
}
} else {
thread = new Thread(this);
thread.start();
}
}
public void run() {
MessageConnection conn = null;
String address= "sms://" + tfNum.getString() + ":" + port;
try {
conn = (MessageConnection) Connector.open(address);
TextMessage msg = (TextMessage)
conn.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setAddress(address);
msg.setPayloadText(tfText.getString());
conn.send(msg);
alert.setString("Sending to " +
address.substring(6));
alert.setType(AlertType.INFO);
display.setCurrent(alert);
} catch (IOException ioe) {
ioe.printStackTrace();
}
if (conn != null) {
try {
conn.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
public TextBox generatePhoneInput() {
TextBox tfPhone = new TextBox("Number?", null,
15, TextField.PHONENUMBER);
tfPhone.addCommand(cmdExit);
tfPhone.addCommand(cmdContinue);
tfPhone.setCommandListener(this);
display.setCurrent(tfPhone);
return tfPhone;
}
public TextBox generateMessageInput() {
TextBox tfMessage = new TextBox("Text Message", null,
500, TextField.ANY);
tfMessage.addCommand(cmdBack);
tfMessage.addCommand(cmdSend);
tfMessage.setCommandListener(this);
display.setCurrent(tfMessage);
return tfMessage;
}
private static boolean isValidPhoneNumber(String number) {
char[] chars = number.toCharArray();
if (chars.length == 0) {
return false;
}
int startPos = 0;
//+
if (chars[0] == '+') {
startPos = 1;
}
for (int i = startPos; i < chars.length; ++i) {
if (!Character.isDigit(chars[i])) {
return false;
}
}
return true;
}
}
Subscribe to:
Post Comments (Atom)
This comment has been removed by the author.
ReplyDeletewe are not getting SMSSender class so we are getting error in receiving code.Can u please help us
ReplyDeleteterima kasih atas scriptnya,,
ReplyDeletemau nanya mas? ada nggak script untuk membuat aplikasi adzan yang berbasis j2me, karena saya lagi butuh ni buat sebagian dari TA saya.
kalo ada tolong mas kirim ke email saya.
syarif_27@yahoo.co.id
makasih...
could you send me the working project pls? (androuis@yahoo.co.uk)
ReplyDeleteQuestion:
ReplyDeleteGimana caranya mengirim pesan ke >1 nomor?
Through j2me i need to connect to Googlemaps
ReplyDeletepls tell me the code to connect to Google maps.
(Specify clearly)...send the code to abhilashbaddam@gmail.com this mail id. Thanks in advance...
sudah di coba, berjalan baik.
ReplyDeletetapi bagaimana script untuk mengirimkan pesan ke beberapa nomor?
yoseph.dani@gmail.com
Ada yang tau gak script dwl atau java untuk buat block sms masuk ke gsm modem seperti maestro, intercel / fastrack
ReplyDeleteangin_16@yahoo.co.id
I want code for sending picture msg not MMS
ReplyDeleteplz mail me
rujul_trivedi07@yahoo.co.in
to j2me developers, Please help how to encrypt sms sending.Please mail me a sample codes if any,Thanks
ReplyDeleteto j2me developers, Please help how to encrypt sms sending.Please mail me a sample codes if any,may email eduardo.delito@yahoo.com Thanks
ReplyDeleteHi there.. Can you send me a working project? please send it to janmichael_bais@yahoo.com.. We need SMS for our thesis though. I'm looking forward for your reply
ReplyDeletehi..
ReplyDeletecan u please tell me how to write into the JAD file?
hi
ReplyDeleteCan you send me code please send it to s.al_tamimi@hotmail.com We need send SMS from computer to mobile (is a text sms) and send turn or off the computer from mobile
and please tell me how to write into the JAD file
please I wetting u
Its Not Working in Real World Env..
ReplyDeleteHow can i know the Port no. of receiver phone???
it may vary from provider to provider..
i need code to send sms from j2me(mobile) to gmail inbox.....plz send me the code...thanks in advance...
ReplyDeletei need code to send sms from j2me(mobile) to gmail inbox.....plz send me the code...thanks in advance... saritha_17041988@rediffmail.com
ReplyDeletei need code to send sms from j2me(mobile) to gmail inbox.....plz send me the code...thanks in advance
ReplyDeletemauga25@yahoo.com
I need code for getting tower information from mobile using j2me pls help me. gunasekaran.arts@gmail.com
ReplyDeletei need a code in browsing inbox messages in j2me..pls..tnx
ReplyDeletecan u please tell me how to write into the JAD file?
ReplyDeleteI NEED CODE FOR BANKING THROUGHT MOBILE...
ReplyDeleteCAN YOU HELP ME??
We need send SMS from computer to mobile (is a text sms) and send turn or off the computer from mobile
ReplyDeletesneharsh10@gmail.com
I need the J2ME source of the data collection mobile server and then mailed to her. Thanks a lot everyone. My email: thuhien_0811@yahoo.com
ReplyDeleteHave an error in public SendSMS() code.Can u please help us
ReplyDeleteMy email: hayvebenanh_boy91@yahoo.com
Have some error
ReplyDelete'{' expected
public class SendSMSextends MIDlet implements Runnable {
and
return type required
public SendSMS() {
can u help us! Thanks!
My email: vovanbacnd@gmail.com
seperate SendSMSextends as SendSMS extend and re-run it.. errors gone
Deleteit shows msg gone bt how to receive it on other phone pls help..
ReplyDeleteFor java seekers...
ReplyDeletecan u send me the working application code?
ReplyDeleteThanx in advance.. (goelritanshu1991@gmail.com)