I am trying to make a J2ME application to send text messages SEND and RECEIVE. I ended up with part of it sending, but I cannot receive any message.
Below I tried to get a text message;
try { MessageConnection conn = (MessageConnection) Connector.open("sms://:50001"); conn.setMessageListener(new MessageListener() { public void notifyIncomingMessage(MessageConnection conn) { try { Message msg; msg = conn.receive(); if (msg instanceof TextMessage) { TextMessage tmsg = (TextMessage) msg; stringItem.setText("Msg: " + tmsg.getPayloadText()); System.out.println(tmsg.getPayloadText()); } // else if(msg instanceof BinaryMessage) { // ..... // } else { // ...... // } } catch (IOException ex) { ex.printStackTrace(); } finally { try { conn.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }); } catch (Exception e1) { System.out.println(e1); }
But this does not work ... Errors do not occur ... what am I doing wrong? ... Can we receive a message using J2ME?
Code for sending message: (UPDATED)
MessageConnection conn = (MessageConnection) Connector.open("sms://:50001"); TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE); tmsg.setPayloadText(message); tmsg.setAddress("sms://" + number); conn.send();
I have send and receive functions in two different forms. What I did was install and run the application on two different mobile phones, send a message from one mobile to another and receive in another.
The message is sent and received successfully, but not in the application. The message is sent to the inbox of another mobile device.
What can I do?
source share