Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.cinterion.io.ATCommand;
- import com.cinterion.io.ATCommandFailedException;
- import com.cinterion.io.ATCommandListener;
- import com.cinterion.io.ATCommandResponseListener;
- /**
- * MIDlet demonstrating the usage of the ATCommand class
- */
- public class Main extends MIDlet {
- private ATCommand m_Cmd;
- private Listener m_Listener = new Listener();
- /**
- * Implementation of ATCommandListener to receive asynchronous events
- */
- private class Listener implements ATCommandListener {
- public void ATEvent(String Event) {
- System.out.println("ATEvent " + Event);
- }
- public void RINGChanged(boolean SignalState) {
- System.out.println("RINGChanged " + SignalState);
- }
- public void DCDChanged(boolean SignalState) {
- System.out.println("DCDChanged " + SignalState);
- }
- public void DSRChanged(boolean SignalState) {
- System.out.println("DSRChanged " + SignalState);
- }
- public void CONNChanged(boolean SignalState) {
- System.out.println("CONNChanged " + SignalState);
- }
- }
- /**
- * Implementation of ATCommandResponseListener to receive asynchronous
- * responses
- */
- private class RspListener implements ATCommandResponseListener {
- public void ATResponse(String Response) {
- System.out.println("Received asynchronous response:");
- System.out.println(Response);
- }
- }
- /**
- * Default constructor
- */
- public Main() {
- System.out.println("Constructor");
- try {
- m_Cmd = new ATCommand(false);
- m_Cmd.addListener(m_Listener);
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
- System.out.println("SmsReceiver stopped");
- notifyDestroyed();
- }
- protected void pauseApp() {
- // TODO Auto-generated method stub
- }
- protected void startApp() throws MIDletStateChangeException {
- System.out.println("Main started");
- try {
- // check the registration
- boolean registered = false;
- while (registered == false) {
- String registration_response = m_Cmd.send("AT+CREG?\r");
- int locally_registered = registration_response.indexOf(",1");
- int roaming_registered = registration_response.indexOf(",5");
- if ((locally_registered > -1) || (roaming_registered > -1)) {
- registered = true;
- System.out.println("Module registered to the network");
- } else {
- System.out.println("Module not registered to the network");
- }
- Thread.sleep(2000);
- }
- sendSMS();
- } catch (Exception e) {
- e.printStackTrace();
- }
- destroyApp(true);
- }
- protected void sendSMS() {
- try {
- String Response = m_Cmd.send("AT+CMGF = 1\r");
- System.out.println(Response);
- Response = m_Cmd.send("AT+CMGS=\"+614********\"\r"); // here you put
- // your nummber
- System.out.println(Response);
- Response = m_Cmd.send("Message \r this is my message from Developer."
- + (char) 26); // here you put text that is inside the SMS
- System.out.println(Response);
- String ctrlZ = (char) 26 + "";
- m_Cmd.send(ctrlZ, new RspListener()); // escapse character, that
- // marks end of SMS content
- } catch (ATCommandFailedException ex) {
- ex.printStackTrace();
- } catch (IllegalStateException ex) {
- ex.printStackTrace();
- } catch (IllegalArgumentException ex) {
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement