Results 1 to 5 of 5
Thread: J2ME sms listener
- 07-03-2009, 08:01 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
J2ME sms listener
Hi
I am doing J2ME application to send and receive sms, but there is a problem while receiving the sms....the message listener doesn't listen to the incoming sms...incoming sms directly goes to the mobile inbox instead of coming to applications, I have set my port number as 5000.....Please give any solutions to receive the sms without port number[From any sms should come to the application]....!
Regards
~Bharani~
- 08-07-2009, 09:03 AM #2
Member
- Join Date
- Aug 2009
- Posts
- 17
- Rep Power
- 0
Hi Bharani,
As you are developing application for sending/receiving sms, then you have to know how it works. J2ME application will listen only those incoming message that comes to specific port (that you defined as 5000). The messages that comes in your OEM inbox folder have default '0' port, you can't take this, it is define only for your native OEM inbox folder. Also you can't read OEM inbox folder messages. So if you want to receive message through application then you have to send message with specific port number like (phone no/port no) 9916292826/5000.
try this and feel free if you have any doubt.
Thanks
Abhijeet Namdeo
- 10-28-2009, 08:53 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
hi
I am new to j2me. I tried the following example.
For sending:-
public class SMSClient2t extends MIDlet
{
protected Display display;
protected Displayable displayable;
public SMSClient2t()
{
display = Display.getDisplay(this);
displayable = new Form("SMS Client");
}
public void startApp() {display.setCurrent(displayable);
try {
String myAddress = "sms://:4";
String hisAddress = "sms://9426729397:4";
String msg = "Hello";
MessageConnection smsconn =
(MessageConnection) Connector.open(myAddress);
TextMessage txtmessage =
(TextMessage)smsconn.newMessage(
MessageConnection.TEXT_MESSAGE);
txtmessage.setPayloadText(msg);
txtmessage.setAddress(hisAddress);
smsconn.send(txtmessage);
// get a reply back. Note, there could be a race
// condition here: while this server is waiting for
// a reply, someone else could send us a message
// which might slip in first... So we should really
// check it is from who we expect
Message replyMsg = smsconn.receive();
if (replyMsg instanceof TextMessage) {
TextMessage tmsg = (TextMessage) replyMsg;
String replyText = tmsg.getPayloadText();
System.out.println("Reply: " + replyText);
}
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
display = null;
displayable = null;
}
}
for receiveing:-
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
/**
* @author vvachhani
*/
public class SMSServer2 extends MIDlet {
protected Display display;
protected Displayable displayable;
protected Form form;
public SMSServer2()
{
display = Display.getDisplay(this);
displayable = form = new Form("SMS Server");
}
public void startApp()
{
display.setCurrent(displayable);
try {
String addr = "sms://:4";
MessageConnection conn = (MessageConnection) Connector.open(addr);
Message msg = null;
while (true) {
// wait for incoming messages
msg = conn.receive(); // received a message
if (msg instanceof TextMessage) {
TextMessage tmsg = (TextMessage) msg;
String receivedText = tmsg.getPayloadText();
form.append(new TextField("Message received", receivedText,
10, TextField.ANY));
// now send the message back
String replyText = "You sent: " + receivedText;
tmsg.setPayloadText(replyText);
conn.send(tmsg);
} else {
// Received message was not a text message, but e.g. binary ...
}
}
} catch (Exception e) {
System.out.println(e.toString());
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional)
{
display = null;
displayable = null;
}
}
I can send the sms with port no but not able to recive it on same port no.
I use nokia 6233 mobile to run this application.
Please tel me how can get i get the port no of mobile?
Thanks
Alpesh shah
- 10-28-2009, 09:37 AM #4
Member
- Join Date
- Aug 2009
- Posts
- 17
- Rep Power
- 0
HI,
The code you are using for receving incoming message with specific port is not correct. You have to implement message listner for that.
Try below mentioned example, Hope it will help you.
Thanks & Regards
Abhijeet Namdeo
Java Code:// Sample message listener program. import java.io.IOException; import javax.microedition.midlet.*; import javax.microedition.io.*; import javax.wireless.messaging.*; public class Example extends MIDlet implements MessageListener { MessageConnection messconn; boolean done; Reader reader; // Initial tests setup and execution. public void startApp() { try { // Get our receiving port connection. messconn = (MessageConnection) Connector.open(“sms://:6222”); // Register a listener for inbound messages. messconn.setMessageListener(this); // Start a message-reading thread. done = false; reader = new Reader(); new Thread(reader).start(); } catch (IOException e) { // Handle startup errors } } // Asynchronous callback for inbound message. public void notifyIncomingMessage(MessageConnection conn) { if (conn == messconn) { reader.handleMessage(); } } // Required MIDlet method - release the connection and // signal the reader thread to terminate. public void pauseApp() { done = true; try { messconn.close(); } catch (IOException e) { // Handle errors } } // Required MIDlet method - shutdown. // @param unconditional forced shutdown flag public void destroyApp(boolean unconditional) { done = true; try { messconn.setMessageListener(null); messconn.close(); } catch (IOException e) { // Handle shutdown errors. } } } // Isolate blocking I/O on a separate thread, so callback // can return immediately. class Reader implements Runnable { private int pendingMessages = 0; // The run method performs the actual message reading. public void run() { while (!done) { synchronized(this) { if (pendingMessages == 0) { try { wait(); } catch (Exception e) { // Handle interruption } } pendingMessages--; } // The benefit of the MessageListener is here. // This thread could via similar triggers be // handling other kind of events as well in // addition to just receiving the messages. try { Message mess = messconn.receive(); } catch (IOException ioe) { // Handle reading errors } } } public synchronized void handleMessage() { pendingMessages++; notify(); } }Last edited by abhijeetrajenamdeo; 10-28-2009 at 09:41 AM.
- 10-31-2009, 07:02 AM #5
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Sending J2ME application by blue tooth (by J2ME application). Very URGENT!!!
By maruffaiz in forum CLDC and MIDPReplies: 0Last Post: 04-22-2009, 01:30 PM -
#key listener problem
By mij1_7 in forum New To JavaReplies: 2Last Post: 02-14-2009, 09:02 PM -
Regarding Listener
By adeeb in forum AWT / SwingReplies: 2Last Post: 06-20-2008, 11:07 PM -
Regarding Listener
By adeeb in forum AWT / SwingReplies: 2Last Post: 06-10-2008, 02:00 AM -
Listener for SWT event
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:04 AM


LinkBack URL
About LinkBacks

Bookmarks