Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-03-2009, 09:01 AM
Member
 
Join Date: Jul 2009
Posts: 2
Rep Power: 0
bharani is on a distinguished road
Thumbs down 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~
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-07-2009, 10:03 AM
Member
 
Join Date: Aug 2009
Posts: 17
Rep Power: 0
abhijeetrajenamdeo is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-28-2009, 09:53 AM
Member
 
Join Date: Oct 2009
Posts: 2
Rep Power: 0
ashah is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-28-2009, 10:37 AM
Member
 
Join Date: Aug 2009
Posts: 17
Rep Power: 0
abhijeetrajenamdeo is on a distinguished road
Default
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


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 10:41 AM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-31-2009, 08:02 AM
Member
 
Join Date: Oct 2009
Posts: 2
Rep Power: 0
ashah is on a distinguished road
Default
hi

Abhijeet thanks for reply. I tried your sugested code but i am not able to recive sms. When i open an applcation it will goes in to catch portion.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Tags
j2me not listening to sms, recieve sms without port

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending J2ME application by blue tooth (by J2ME application). Very URGENT!!! maruffaiz CLDC and MIDP 0 04-22-2009 02:30 PM
#key listener problem mij1_7 New To Java 2 02-14-2009 10:02 PM
Regarding Listener adeeb AWT / Swing 2 06-21-2008 12:07 AM
Regarding Listener adeeb AWT / Swing 2 06-10-2008 03:00 AM
Listener for SWT event Java Tip Java Tips 0 01-08-2008 10:04 AM


All times are GMT +2. The time now is 06:44 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org