I tried an example to receive sms. The program throwed an exception. Same thing happened for the example in SMSReceive under WMADemo. It says
java/lang/IllegalArgumentException Port number format error
I tried an example to receive sms. The program throwed an exception. Same thing happened for the example in SMSReceive under WMADemo. It says
java/lang/IllegalArgumentException Port number format error
Last edited by csckid; 2010-07-25 at 19:08.
I will appreciate if you could let us know the exact line of code where you are trying to open the SMS connection.
I suspect that you forget to mention the port number onside the jad attributes, since that code reads the same from the Jad file.Kindly add the attributes and check the same.I am sure that this issue will be fixed.
Thanks with Regards,
R a j - The K e r n e l
Join Delhi-NCR Nokia Developer's Community,
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package newpackage;
import java.io.IOException;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.wireless.messaging.*;
/**
* An example MIDlet displays text from an SMS MessageConnection
* BY DEEPAK KINNI
*/
public class SMSReceive extends MIDlet implements CommandListener, Runnable, MessageListener {
Command exitCommand = new Command("Exit", Command.EXIT, 2);
Alert content;
Display display;
Thread thread;
String[] connections;
boolean done;
String smsPort;
MessageConnection smsconn;
Message msg;
String senderAddress;
Displayable resumeScreen;
String txtInHex;
byte [] txtInByte;
int len;
public SMSReceive() {
smsPort = getAppProperty("SMS-Port");
display = Display.getDisplay(this);
content = new Alert("SMS Receive");
content.setTimeout(Alert.FOREVER);
content.addCommand(exitCommand);
content.setCommandListener(this);
content.setString("Receiving...");
resumeScreen = content;
}
public void startApp() {
String smsConnection = "sms://:" + smsPort;
if (smsconn == null) {
try {
smsconn = (MessageConnection)Connector.open(smsConnection);
smsconn.setMessageListener(this);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
connections = PushRegistry.listConnections(true);
if ((connections == null) || (connections.length == 0)) {
content.setString("Waiting for SMS on port " + smsPort + "...");
}
done = false;
thread = new Thread(this);
thread.start();
display.setCurrent(resumeScreen);
}
public void notifyIncomingMessage(MessageConnection conn) {
if (thread == null) {
done = false;
thread = new Thread(this);
thread.start();
}
}
public void run() {
try {
msg = smsconn.receive();
if (msg != null) {
senderAddress = msg.getAddress();
content.setTitle("From: " + senderAddress);
if (msg instanceof TextMessage) {
txtInHex=((TextMessage)msg).getPayloadText();
}else {
StringBuffer buf = new StringBuffer();
byte[] data = ((BinaryMessage)msg).getPayloadData();
for (int i = 0; i < data.length; i++) {
int intData = (int)data[i] & 0xFF;
if (intData < 0x10) {
buf.append("0");
}
buf.append(Integer.toHexString(intData));
//buf.append(' ');
}
txtInHex=(buf.toString());
}
txtInByte = new byte [txtInHex.length() / 2];
int j = 0;
for (int i = 0; i < txtInHex.length()-2; i += 2)
{
txtInByte[j++] = Byte.parseByte(txtInHex.substring(i,i+2),16);
}
String txt = new String(txtInByte);
content.setString(txt);
display.setCurrent(content);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void pauseApp() {
done = true;
thread = null;
resumeScreen = display.getCurrent();
}
public void destroyApp(boolean unconditional) {
done = true;
thread = null;
if (smsconn != null) {
try {
smsconn.close();
} catch (IOException e) {
}
}
}
public void commandAction(Command c, Displayable s) {
try {
if ((c == exitCommand) || (c == Alert.DISMISS_COMMAND)) {
destroyApp(false);
notifyDestroyed();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Thats the program!!!...BTW the program accepts HEX data nd den converts it into ASCII....my assignment required me to do that!!
anyways apart from jus typing in the code you have to also go the Application Descriptor option and insert specific PORT NUMBER into the field,
Then go to Push Registry option also register there...
the logic here is:see when you receive a message it has two address:the mobile number,port number...so what happens is you usually
specify the mobile no. when it reaches the cell it by default goes to the INBOX if you also specify the port number what will happen is as soon as the
message is received it invokes the App and uses your Apps default way of showing the incoming message!!
I ve written all these things coz you MIGHT face all these problems wen go ahead!...![]()