i don't know how to read received messages in mobile device using J2ME midlet.Actually I have been sending the messages to other mobiles using SMS gateway.The sms gateway reply to the same mobile device,but i want to read the reply message on the device directly, not going to check the inbox.how to do this in j2me midlet using the PushRegistry
concept.please give me the good idea or sample code for me...thanks in advance.
Asked
Active
Viewed 1,652 times
1
-
[Read SMS from In-Box](http://stackoverflow.com/a/10645996/996493) – Lucifer Sep 26 '12 at 16:31
1 Answers
3
You should use the PushRegistry mechanism for this. In order to do so, you should mark in the .jad file that your application reacts to incoming SMS and also mark the SMS permission. Put these properties to the JAD file:
MIDlet-Push-1: sms://:10214,hu.bute.daai.example.sms.MidletSMSPushDemo,*
MIDlet-Permissions: javax.microedition.io.PushRegistry, javax.microedition.io.Connector.sms, javax.wireless.messaging.sms.receive
Please note that you should use your own package and MIDlet name. In addition to that you should use the same port for SMS sending as it was defined in the JAD (10214 in the example).
After that when your MIDlet starts, you should call your SMS receiver code to get the SMS:
public class MidletJSMSProxy extends MIDlet {
public void startApp() {
initalize();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void initSMSReceive() {
new Thread() {
public void run() {
MessageConnection conn = null;
try {
String url = "sms://:10214";
MessageConnection conn = (MessageConnection) Connector.open(url);
TextMessage message = (TextMessage)conn.receive();
System.out.println("SMS: "+message.getAddress()+" - "+message.getPayloadText());
}
catch(Exception e){
e.printStackTrace();
} finally {
try {
if (conn != null)
conn.close();
} catch(Exception e){
e.printStackTrace();
}
}
}
}.start();
}
}