Advertisement
Guest User

SMSHandler

a guest
Oct 25th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.InputStream;
  3. import java.io.OutputStream;
  4.  
  5. import javax.microedition.io.CommConnection;
  6. import javax.microedition.io.Connector;
  7. import javax.microedition.midlet.*;
  8.  
  9.  
  10. import SerialHandler;
  11. import SocketServidor;
  12. import SocketServidorC;
  13. import com.cinterion.io.ATCommand;
  14. import com.cinterion.io.ATCommandFailedException;
  15. import com.cinterion.io.ATCommandListener;
  16.  
  17. public class SMSHandler extends MIDletStateChangeException
  18. {  
  19.     String numero = null;
  20.     String mensagem = null;
  21.     private ATCommand atc;
  22.    
  23.  
  24. public SMSHandler()
  25.  
  26. {
  27. }
  28.        
  29.  
  30. public void run() throws IllegalStateException, IllegalArgumentException, ATCommandFailedException
  31. {        
  32.    
  33.  
  34.          atc = new ATCommand(false);
  35.          ATCommandListener listener = new ATCommandListener() {
  36.          public void RINGChanged(boolean SignalState) {
  37.          }
  38.          public void DSRChanged(boolean SignalState) {
  39.          }
  40.          public void DCDChanged(boolean SignalState) {
  41.          }
  42.          public void CONNChanged(boolean SignalState) {
  43.          }
  44.          public void ATEvent(final String Event) {
  45.                 System.out.println("received URC: " + Event);
  46.  
  47.               // search for SMS related URCs
  48.                  if (Event.indexOf("+CMTI") > 0) {
  49.                      //String content = getSmsContent(Event, false);
  50.                      //System.out.println("Sms content: " + content);
  51.                      System.out.println("Sms content: ");
  52.                      }
  53.          }
  54.        };
  55.  
  56.       // add (activate) the listener
  57.       atc.addListener(listener);
  58.  
  59.     //  switch to the text mode
  60.       System.out.println(atc.send("at+cmgf=1\r"));
  61.     // ENVIO DA SMS
  62.       String at_cmd_response = atc.send("AT+CMGS=\""+ "00" + numero +"\"\r");
  63.  
  64.       System.out.println(at_cmd_response);
  65.    // provide the message text & confirm (terminate)
  66.       at_cmd_response = atc.send( mensagem + (char) 26);
  67.  
  68.       // show the response on the screen
  69.       System.out.println(at_cmd_response);
  70.       // activate the SMS URCs
  71.       //System.out.println(atc.send("at+cnmi=2,1\r"));
  72. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement