/* This example for sending sms using our SIM card.
Here im not using any PORT No to send the sms. so the received sms will be displayed in Inbox. This sms will be sent by using your sim card. so you will be charged for the same..*/
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.wireless.messaging.*;
public class SendSms extends MIDlet implements CommandListener {
Display display;
private TextField toWhom;
private TextField message;
private Alert alert;
private Command send,exit;
MessageConnection clientConn;
private Form compose;
public SendSms() {
display=Display.getDisplay(this);
compose=new Form("Compose Message");
toWhom=new TextField("To","",10,TextField.PHONENUMBER);
message=new TextField("Message","",600,TextField.ANY);
send=new Command("Send",Command.BACK,0);
exit=new Command("Exit",Command.SCREEN,5);
compose.append(toWhom);
compose.append(message);
compose.addCommand(send);
compose.addCommand(exit);
compose.setCommandListener(this);
}
public void startApp() {
display.setCurrent(compose);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void commandAction(Command cmd,Displayable disp) {
if(cmd==exit) {
destroyApp(false);
}
if(cmd==send) {
String mno=toWhom.getString();
String msg=message.getString();
if(mno.equals("")) {
alert = new Alert("Alert");
alert.setString("Enter Mobile Number!!!");
alert.setTimeout(2000);
display.setCurrent(alert);
}
else {
try {
clientConn=(MessageConnection)Connector.open("sms://"+mno);
}
catch(Exception e) {
alert = new Alert("Alert");
alert.setString("Unable to connect to Station because of network problem");
alert.setTimeout(2000);
display.setCurrent(alert);
}
try {
TextMessage textmessage = (TextMessage) clientConn.newMessage(MessageConnection.TEXT_MESSAGE);
textmessage.setAddress("sms://"+mno);
textmessage.setPayloadText(msg);
clientConn.send(textmessage);
}
catch(Exception e)
{
Alert alert=new Alert("Alert","",null,AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
alert.setString("Unable to send");
display.setCurrent(alert);
}
}
}
}
}
Thursday, July 5, 2012
Subscribe to:
Post Comments (Atom)
Popular Posts
-
I spent a long time to config them. so tired, but now it run very good. It's work. Step 1: Download Source PhoneGap at PhoneGap.com...
-
Để chuyển 1 file .app sang .ipa đầu tiên các bận cần có là 1 file .app, trong hướng dẫn mình sử dụng file Tuvi.app 1. Mở xcode len 2. Men...
-
Trong bài này mình sẽ giới thiệu với các bạn về lập trình Socket(bài này mình chỉ nói đến lập trình Socket cho TCP/IP) trong Android. Lập ...
-
Xử lý ngày tháng trong PHP Trừ ngày $date = "2009-03-02"; $new_date = strtotime ( '-2 day' , strtotime ( $date ) ) ; ...
No comments:
Post a Comment