/* * Copyright (C) 2009 E.Albert, P.Arenas, S.Genaim, G.Puebla, and D.Zanardini * https://costa.ls.fi.upm.es * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package midp; /** * This class contains a MIDlet that sends an sms to a mobile phone * also this MIDP application can be installed in a mobile device. * @author Diana Ramírez * */ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import javax.wireless.messaging.*; import java.io.*; //A first MIDlet with simple text and a few commands. public class Message extends MIDlet implements CommandListener, MessageListener { //The exit command private Command exitCommand; //Command to send the Message private Command sendMsgCommand; //The display for this MIDlet private Display display; Form displayForm; String msgToSend="sms Test !"; MessageConnection clientConn; public Message() { display = Display.getDisplay(this); exitCommand = new Command("Exit", Command.SCREEN, 1); sendMsgCommand = new Command("Send", Command.SCREEN, 1); } public void notifyIncomingMessage(MessageConnection conn) { } // Start the MIDlet by creating the TextBox and // associating the exit command and listener. public void startApp() { displayForm = new Form("Send Message"); displayForm.addCommand(exitCommand); displayForm.addCommand(sendMsgCommand); displayForm.setCommandListener(this); // displayForm.setItemStateListener(); display.setCurrent(displayForm); try { clientConn = (MessageConnection)Connector.open("sms://+34697396559"); } catch (IOException ioExc) { System.out.println("Client connection could be obtained"); ioExc.printStackTrace(); } } // Pause is a no-op because there is no background // activities or record stores to be closed. public void pauseApp() { } // Destroy must cleanup everything not handled // by the garbage collector. public void destroyApp(boolean unconditional) { } // Respond to commands. public void commandAction( Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } if (c == sendMsgCommand) { try { TextMessage tmsg =(TextMessage)clientConn.newMessage(MessageConnection.TEXT_MESSAGE); tmsg.setAddress("sms://+34697396559"); tmsg.setPayloadText(msgToSend); clientConn.send(tmsg); } catch (Exception exc) { exc.printStackTrace(); } } } }