Gemalto is now part of the Thales Group, find out more.

You are here

SMS Monitor in Java Midlet | Thales IoT Developer Community

luke_maxon

March 28, 2017 - 7:34am, 1480 views

Hi,

I am trying to make a quite simple java midlet to monitor incoming SMS in EHS6 and I borrowed the code from the fotamidlet example which has the simlar functions. I used updater.java and removed those unwanted functions only left "startSmsMonitor()".

In the main.java. is like this:

protected void startApp() throws MIDletStateChangeException {

System.out.println("startApp");

try {

final ATCommand atc = new ATCommand(false);

System.out.println(atc.send("AT+CNMI=2,1\r"));      // Enable SMS URC

try {

Updater.startSmsMonitor();      // Start Monitor

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

final ATCommand atc2 = new ATCommand(false);

t = new Thread() {

public void run() {

int counter = 0;

try {

GsmUtils.switchToTextMode();

} catch (Exception e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

while (true) {

try {

System.out.println(GsmUtils.sendSms(Main.this.getAppProperty("SmsNumber"), "QuarySms"));    // Periodically sending an quary SMS to another modem

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

Thread.sleep((Integer.parseInt(Main.this.getAppProperty("SmsPeriod")) * 1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

};

};

t.start();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

However the above code did not work. The Midlet didn't get ATEvent() trggered when an SMS was coming in. I could seen the received SMS by +CMGL. What did I miss in the code? Thanks.