Skip to main content

SMS Tut

8 replies [Last post]
Anonymous

Hello anyone,
Please suggest me some tutorials for sms programming in j2me.
I don't have absolutely any idea regarding this.

Thanks
R.Naik

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
terrencebarr
Offline
Joined: 2004-03-04
Points: 0

Hey Ian,

Thanks for getting involved and sharing your code and experience with the community! This is the kind of participation that makes the community.

The examples you've been posting would work well for the repository we're starting to build. We're aiming at collecting code, examples, tips and whatever snippets and info ME developers consider useful. See https://meapplicationdevelopers.dev.java.net/call_for_applications.html

Would you be interested in helping us on this (beginning with your SMS code)? Let me know.

Thanks,

-- Terrence

Terrence Barr
Evangelist, Java Mobile & Embedded Community
Sun Microsystems, Germany
www.mobileandembedded.org

Raghavendra K. Naik

Hello ian,
Thanks for sending following sources. Now how do I need to deploy it
within my wireless tool kit.
What initial settings do I need to do inorder to get this example
working ?

Thanks,
R.Naik

-----Original Message-----
From: A mailing list for KVM discussion
[mailto:KVM-INTEREST@JAVA.SUN.COM] On Behalf Of Ian Strain
Sent: 07 December 2006 17:57
To: KVM-INTEREST@JAVA.SUN.COM
Subject: Re: SMS Tut

here is a send sms midlet:

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;

public class SmsSend extends MIDlet implements CommandListener, Runnable
{

private Display display;

private Form firstScreen;
private TextField phoneNumber;
private TextField messageText;
private TextField portNumber;
private ChoiceGroup binOrText;

private Command exitMIDlet;
private Command sendMessage;

private boolean sendBinary = false;

private static final int PORTNUMBER = 50000;

public SmsSend() {
exitMIDlet = new Command("Exit", Command.EXIT, 1);
sendMessage = new Command("Send message", Command.SCREEN, 1);

String[] elements = {"Text", "Binary"};
binOrText = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE, elements,
null);

firstScreen = new Form("New message to be sent:");
phoneNumber = new TextField("number:",null,64,TextField.PHONENUMBER);
messageText = new TextField("message:",null,64,TextField.ANY);
portNumber = new TextField("port:",null,64,TextField.NUMERIC);
firstScreen.append(phoneNumber);
firstScreen.append(messageText);
firstScreen.append(portNumber);
firstScreen.append(binOrText);
firstScreen.addCommand(exitMIDlet);
firstScreen.addCommand(sendMessage);
firstScreen.setCommandListener(this);
}

protected void startApp() {
display = Display.getDisplay(this);
display.setCurrent(firstScreen);
}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable s) {

if (c == exitMIDlet) {
destroyApp(true);
notifyDestroyed();
return;
}

if(c == sendMessage){
if(binOrText.isSelected(0)) {
sendBinary = false;
} else {
sendBinary = true;
}

String number = phoneNumber.getString();
String text = messageText.getString();
String port = portNumber.getString();

Thread t = new Thread(this);
t.start();
}
}

public void run() {
String url;
MessageConnection connection = null;
TextMessage message = null;
BinaryMessage b_message = null;

String number = phoneNumber.getString();
String text = messageText.getString();
String port = portNumber.getString();

url = "sms://" + number + ":" + port;

if(!port.equals("")) {
try {
connection = (MessageConnection) Connector.open(url);
if(!sendBinary) {
message =
(TextMessage)connection.newMessage(MessageConnection.TEXT_MESSAGE);
message.setPayloadText(text);
connection.send(message);
} else {
b_message =
(BinaryMessage)connection.newMessage(MessageConnection.BINARY_MESSAGE);
b_message.setPayloadData(text.getBytes());
connection.send(b_message);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(connection != null)
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}

and here is an sms receive midlet:

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import javax.wireless.messaging.*;

public class SmsReceive extends MIDlet implements CommandListener,
Runnable {
MessageConnection connection;
String payload;
String url;
Form form;

private Display display;

private Form firstScreen;
private StringItem phoneNumber;
private StringItem messageText;
private StringItem portNum;
private TextField portNumber;

private Alert secondScreen;

private Command exitMIDlet;
Command back;

private static int PORTNUMBER = 50000;

public SmsReceive() {
exitMIDlet = new Command("Exit", Command.EXIT, 1);
back = new Command("Back", Command.BACK, 1);

firstScreen = new Form("New message received:");
phoneNumber = new StringItem("number:",null);
messageText = new StringItem("message:",null);
portNum = new StringItem("port:",null);
portNumber = new TextField("port:",null,64,TextField.NUMERIC);
firstScreen.append(phoneNumber);
firstScreen.append(messageText);
firstScreen.append(portNum);
firstScreen.addCommand(exitMIDlet);
firstScreen.addCommand(back);
firstScreen.setCommandListener(this);

secondScreen = new Alert("Alert"," New message!",null,AlertType.INFO);
secondScreen.setTimeout(Alert.FOREVER);
}

protected void startApp() {
display = Display.getDisplay(this);
form = new Form("Receive");
form.append(portNumber);
Command cmd = new Command("Enter", Command.OK, 1);
form.addCommand(cmd);
form.setCommandListener(this);
display.setCurrent(form);
}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable s) {
if(c.getLabel().equals("Enter")) {
if(!portNumber.getString().equals(" ")) {
try {
PORTNUMBER = Integer.parseInt(portNumber.getString());
} catch (NumberFormatException nfe) {
System.out.println("Exception: " + nfe);
}
}
url = "sms://"+":"+ PORTNUMBER;
portNum.setText("" + PORTNUMBER);

Thread t = new Thread(this);
t.start();
display.setCurrent(firstScreen);
}
if (c == exitMIDlet) {
destroyApp(true);
notifyDestroyed();
return;
}

if(c == back) {
display.setCurrent(form);
}
}

public void run() {
connection = null;
Message message;
TextMessage textMessage;
BinaryMessage binaryMessage;
String number;
String text;

try {
connection = (MessageConnection) Connector.open(url);
while(true) {
message = connection.receive();
number = message.getAddress();
phoneNumber.setText(number);
if(message instanceof TextMessage){
textMessage = (TextMessage)message;
text = textMessage.getPayloadText();
} else {
BinaryMessage binary = (BinaryMessage)message;
byte[] data = binary.getPayloadData();
text = new String(data, "UTF-8");
}
messageText.setText(text);
}
} catch (Exception e) {
e.printStackTrace();
try {
if(connection != null)
connection.close();
} catch(Exception e1) {
e1.printStackTrace();
}
return;
}
}
}

and here is an sms receive midlet using a MessageListener

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import javax.wireless.messaging.*;

public class SmsReceiveListener extends MIDlet implements
CommandListener, Runnable, MessageListener {
MessageConnection connection;
String payload;
String url;
Form form;

private Display display;

private Form firstScreen;
private StringItem phoneNumber;
private StringItem messageText;
private StringItem portNum;
private TextField portNumber;

private Alert secondScreen;

private Command exitMIDlet;
Command back;

private static int PORTNUMBER = 50000;

public SmsReceiveListener() {
exitMIDlet = new Command("Exit", Command.EXIT, 1);
back = new Command("Back", Command.BACK, 1);

firstScreen = new Form("New message received:");
phoneNumber = new StringItem("number:",null);
messageText = new StringItem("message:",null);
portNum = new StringItem("port:",null);
portNumber = new TextField("port:",null,64,TextField.NUMERIC);
firstScreen.append(phoneNumber);
firstScreen.append(messageText);
firstScreen.append(portNum);
firstScreen.addCommand(exitMIDlet);
firstScreen.addCommand(back);
firstScreen.setCommandListener(this);

secondScreen = new Alert("Alert"," New message!",null,AlertType.INFO);
secondScreen.setTimeout(Alert.FOREVER);
}

protected void startApp() {
display = Display.getDisplay(this);
form = new Form("Receive");
form.append(portNumber);
Command cmd = new Command("Enter", Command.OK, 1);
form.addCommand(cmd);
form.setCommandListener(this);
display.setCurrent(form);
}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable s) {
if(c.getLabel().equals("Enter")) {
if(!portNumber.getString().equals(" ")) {
try {
PORTNUMBER = Integer.parseInt(portNumber.getString());
} catch (NumberFormatException nfe) {
System.out.println("Exception: " + nfe);
}
}
url = "sms://"+":"+ PORTNUMBER;
portNum.setText("" + PORTNUMBER);

MessengerThread msg = new MessengerThread();
msg.start();

Thread t = new Thread(this);
t.start();
display.setCurrent(firstScreen);
}
if (c == exitMIDlet) {
destroyApp(true);
notifyDestroyed();
return;
}

if(c == back) {
display.setCurrent(form);
}
}

public void run() {
connection = null;
Message message;
TextMessage textMessage;
BinaryMessage binaryMessage;
String number;
String text;

try {
connection = (MessageConnection) Connector.open(url);
connection.setMessageListener(this);
} catch (Exception e) {
e.printStackTrace();
try {
if(connection != null)
connection.close();
} catch(Exception e1) {
e1.printStackTrace();
}
return;
}
}

public void notifyIncomingMessage(MessageConnection msgConn) {
MessengerThread t = new MessengerThread();
t.start();
}

private class MessengerThread extends Thread {
private Message msg;

public MessengerThread(Message msg) {
this.msg = msg;
}

public MessengerThread() {
this.msg = null;
}

public void run() {
String number;
try {
if (msg == null) {
Message msg = connection.receive();

number = msg.getAddress();
phoneNumber.setText(number);

if (msg instanceof BinaryMessage) {
BinaryMessage binary = (BinaryMessage)msg;
byte[] data = binary.getPayloadData();
payload = new String(data, "UTF-8");
} else if (msg instanceof TextMessage) {
TextMessage text = (TextMessage)msg;
payload = text.getPayloadText();
}
messageText.setText(payload);
} else {
connection.send(msg);
}
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage());
}
}
}
}

I just happen to be working on sms at the moment!!

Share the wealth!

Raghavendra K. Naik wrote:
>
> Hello anyone,
> Please suggest me some tutorials for sms programming in j2me.
> I don't have absolutely any idea regarding this.
>
> Thanks
> R.Naik
>
>
========================================================================
===
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body of the message "signoff KVM-INTEREST". For general help, send
> email to listserv@java.sun.com and include in the body of the message
> "help".

========================================================================
===
To unsubscribe, send email to listserv@java.sun.com and include in the
body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Ian Strain

here is a send sms midlet:

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;

public class SmsSend extends MIDlet implements CommandListener, Runnable {

private Display display;

private Form firstScreen;
private TextField phoneNumber;
private TextField messageText;
private TextField portNumber;
private ChoiceGroup binOrText;

private Command exitMIDlet;
private Command sendMessage;

private boolean sendBinary = false;

private static final int PORTNUMBER = 50000;

public SmsSend() {
exitMIDlet = new Command("Exit", Command.EXIT, 1);
sendMessage = new Command("Send message", Command.SCREEN, 1);

String[] elements = {"Text", "Binary"};
binOrText = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE, elements, null);

firstScreen = new Form("New message to be sent:");
phoneNumber = new TextField("number:",null,64,TextField.PHONENUMBER);
messageText = new TextField("message:",null,64,TextField.ANY);
portNumber = new TextField("port:",null,64,TextField.NUMERIC);
firstScreen.append(phoneNumber);
firstScreen.append(messageText);
firstScreen.append(portNumber);
firstScreen.append(binOrText);
firstScreen.addCommand(exitMIDlet);
firstScreen.addCommand(sendMessage);
firstScreen.setCommandListener(this);
}

protected void startApp() {
display = Display.getDisplay(this);
display.setCurrent(firstScreen);
}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable s) {

if (c == exitMIDlet) {
destroyApp(true);
notifyDestroyed();
return;
}

if(c == sendMessage){
if(binOrText.isSelected(0)) {
sendBinary = false;
} else {
sendBinary = true;
}

String number = phoneNumber.getString();
String text = messageText.getString();
String port = portNumber.getString();

Thread t = new Thread(this);
t.start();
}
}

public void run() {
String url;
MessageConnection connection = null;
TextMessage message = null;
BinaryMessage b_message = null;

String number = phoneNumber.getString();
String text = messageText.getString();
String port = portNumber.getString();

url = "sms://" + number + ":" + port;

if(!port.equals("")) {
try {
connection = (MessageConnection) Connector.open(url);
if(!sendBinary) {
message =
(TextMessage)connection.newMessage(MessageConnection.TEXT_MESSAGE);
message.setPayloadText(text);
connection.send(message);
} else {
b_message =
(BinaryMessage)connection.newMessage(MessageConnection.BINARY_MESSAGE);
b_message.setPayloadData(text.getBytes());
connection.send(b_message);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(connection != null)
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}

and here is an sms receive midlet:

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import javax.wireless.messaging.*;

public class SmsReceive extends MIDlet implements CommandListener,
Runnable {
MessageConnection connection;
String payload;
String url;
Form form;

private Display display;

private Form firstScreen;
private StringItem phoneNumber;
private StringItem messageText;
private StringItem portNum;
private TextField portNumber;

private Alert secondScreen;

private Command exitMIDlet;
Command back;

private static int PORTNUMBER = 50000;

public SmsReceive() {
exitMIDlet = new Command("Exit", Command.EXIT, 1);
back = new Command("Back", Command.BACK, 1);

firstScreen = new Form("New message received:");
phoneNumber = new StringItem("number:",null);
messageText = new StringItem("message:",null);
portNum = new StringItem("port:",null);
portNumber = new TextField("port:",null,64,TextField.NUMERIC);
firstScreen.append(phoneNumber);
firstScreen.append(messageText);
firstScreen.append(portNum);
firstScreen.addCommand(exitMIDlet);
firstScreen.addCommand(back);
firstScreen.setCommandListener(this);

secondScreen = new Alert("Alert"," New message!",null,AlertType.INFO);
secondScreen.setTimeout(Alert.FOREVER);
}

protected void startApp() {
display = Display.getDisplay(this);
form = new Form("Receive");
form.append(portNumber);
Command cmd = new Command("Enter", Command.OK, 1);
form.addCommand(cmd);
form.setCommandListener(this);
display.setCurrent(form);
}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable s) {
if(c.getLabel().equals("Enter")) {
if(!portNumber.getString().equals(" ")) {
try {
PORTNUMBER = Integer.parseInt(portNumber.getString());
} catch (NumberFormatException nfe) {
System.out.println("Exception: " + nfe);
}
}
url = "sms://"+":"+ PORTNUMBER;
portNum.setText("" + PORTNUMBER);

Thread t = new Thread(this);
t.start();
display.setCurrent(firstScreen);
}
if (c == exitMIDlet) {
destroyApp(true);
notifyDestroyed();
return;
}

if(c == back) {
display.setCurrent(form);
}
}

public void run() {
connection = null;
Message message;
TextMessage textMessage;
BinaryMessage binaryMessage;
String number;
String text;

try {
connection = (MessageConnection) Connector.open(url);
while(true) {
message = connection.receive();
number = message.getAddress();
phoneNumber.setText(number);
if(message instanceof TextMessage){
textMessage = (TextMessage)message;
text = textMessage.getPayloadText();
} else {
BinaryMessage binary = (BinaryMessage)message;
byte[] data = binary.getPayloadData();
text = new String(data, "UTF-8");
}
messageText.setText(text);
}
} catch (Exception e) {
e.printStackTrace();
try {
if(connection != null)
connection.close();
} catch(Exception e1) {
e1.printStackTrace();
}
return;
}
}
}

and here is an sms receive midlet using a MessageListener

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import javax.wireless.messaging.*;

public class SmsReceiveListener extends MIDlet implements
CommandListener, Runnable, MessageListener {
MessageConnection connection;
String payload;
String url;
Form form;

private Display display;

private Form firstScreen;
private StringItem phoneNumber;
private StringItem messageText;
private StringItem portNum;
private TextField portNumber;

private Alert secondScreen;

private Command exitMIDlet;
Command back;

private static int PORTNUMBER = 50000;

public SmsReceiveListener() {
exitMIDlet = new Command("Exit", Command.EXIT, 1);
back = new Command("Back", Command.BACK, 1);

firstScreen = new Form("New message received:");
phoneNumber = new StringItem("number:",null);
messageText = new StringItem("message:",null);
portNum = new StringItem("port:",null);
portNumber = new TextField("port:",null,64,TextField.NUMERIC);
firstScreen.append(phoneNumber);
firstScreen.append(messageText);
firstScreen.append(portNum);
firstScreen.addCommand(exitMIDlet);
firstScreen.addCommand(back);
firstScreen.setCommandListener(this);

secondScreen = new Alert("Alert"," New message!",null,AlertType.INFO);
secondScreen.setTimeout(Alert.FOREVER);
}

protected void startApp() {
display = Display.getDisplay(this);
form = new Form("Receive");
form.append(portNumber);
Command cmd = new Command("Enter", Command.OK, 1);
form.addCommand(cmd);
form.setCommandListener(this);
display.setCurrent(form);
}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable s) {
if(c.getLabel().equals("Enter")) {
if(!portNumber.getString().equals(" ")) {
try {
PORTNUMBER = Integer.parseInt(portNumber.getString());
} catch (NumberFormatException nfe) {
System.out.println("Exception: " + nfe);
}
}
url = "sms://"+":"+ PORTNUMBER;
portNum.setText("" + PORTNUMBER);

MessengerThread msg = new MessengerThread();
msg.start();

Thread t = new Thread(this);
t.start();
display.setCurrent(firstScreen);
}
if (c == exitMIDlet) {
destroyApp(true);
notifyDestroyed();
return;
}

if(c == back) {
display.setCurrent(form);
}
}

public void run() {
connection = null;
Message message;
TextMessage textMessage;
BinaryMessage binaryMessage;
String number;
String text;

try {
connection = (MessageConnection) Connector.open(url);
connection.setMessageListener(this);
} catch (Exception e) {
e.printStackTrace();
try {
if(connection != null)
connection.close();
} catch(Exception e1) {
e1.printStackTrace();
}
return;
}
}

public void notifyIncomingMessage(MessageConnection msgConn) {
MessengerThread t = new MessengerThread();
t.start();
}

private class MessengerThread extends Thread {
private Message msg;

public MessengerThread(Message msg) {
this.msg = msg;
}

public MessengerThread() {
this.msg = null;
}

public void run() {
String number;
try {
if (msg == null) {
Message msg = connection.receive();

number = msg.getAddress();
phoneNumber.setText(number);

if (msg instanceof BinaryMessage) {
BinaryMessage binary = (BinaryMessage)msg;
byte[] data = binary.getPayloadData();
payload = new String(data, "UTF-8");
} else if (msg instanceof TextMessage) {
TextMessage text = (TextMessage)msg;
payload = text.getPayloadText();
}
messageText.setText(payload);
} else {
connection.send(msg);
}
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage());
}
}
}
}

I just happen to be working on sms at the moment!!

Share the wealth!

Raghavendra K. Naik wrote:
>
> Hello anyone,
> Please suggest me some tutorials for sms programming in j2me.
> I don’t have absolutely any idea regarding this.
>
> Thanks
> R.Naik
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body of the message "signoff KVM-INTEREST". For general help, send
> email to listserv@java.sun.com and include in the body of the message
> "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Phani K

Hi

Check out

http://developers.sun.com/techtopics/mobility/midp/articles/wma/index.ht
ml

HTH

Koka Phani

________________________________

From: A mailing list for KVM discussion
[mailto:KVM-INTEREST@JAVA.SUN.COM] On Behalf Of Raghavendra K. Naik
Sent: Thursday, December 07, 2006 4:06 PM
To: KVM-INTEREST@JAVA.SUN.COM
Subject: SMS Tut

Hello anyone,
Please suggest me some tutorials for sms programming in j2me.
I don't have absolutely any idea regarding this.

Thanks
R.Naik

========================================================================
=== To unsubscribe, send email to listserv@java.sun.com and include in
the body of the message "signoff KVM-INTEREST". For general help, send
email to listserv@java.sun.com and include in the body of the message
"help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

C. Enrique Ortiz

Or better, the WMA 2.0 version of it:

http://developers.sun.com/techtopics/mobility/midp/articles/wma2/

> Hi
>
> Check out
>
>
>
> http://developers.sun.com/techtopics/mobility/midp/articles/wma/index.ht
> ml
>
>
>
> HTH
>
> Koka Phani
>
>
>
> ________________________________
>
> From: A mailing list for KVM discussion
> [mailto:KVM-INTEREST@JAVA.SUN.COM] On Behalf Of Raghavendra K. Naik
> Sent: Thursday, December 07, 2006 4:06 PM
> To: KVM-INTEREST@JAVA.SUN.COM
> Subject: SMS Tut
>
>
>
> Hello anyone,
> Please suggest me some tutorials for sms programming in j2me.
> I don't have absolutely any idea regarding this.
>
> Thanks
> R.Naik
>
> ========================================================================
> === To unsubscribe, send email to listserv@java.sun.com and include in
> the body of the message "signoff KVM-INTEREST". For general help,
> send email to listserv@java.sun.com and include in the body of the message
> "help".
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in
> the body of the message "signoff KVM-INTEREST". For general help,
> send email to listserv@java.sun.com and include in the body of the
> message "help".
>
> --------------------------------
> Spam/Virus scanning by CanIt Pro
>
> For more information see
> http://www.kgbinternet.com/SpamFilter.htm
>
> To control your spam filter, log in at
> http://filter.kgbinternet.com

--
Open WebMail Project (http://openwebmail.org)

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

C. Enrique Ortiz

go to: http://wireless.java.sun.com and search there, and/or http://cenriqueortiz.com, or just ask Google! :-)

----
ceo
(sent from my mobile)

-----Original Message-----

From: "Raghavendra K. Naik"
Subj: SMS Tut
Date: Thu Dec 7, 2006 6:24 am
Size: 675 bytes
To: KVM-INTEREST@JAVA.SUN.COM

Hello anyone,
Please suggest me some tutorials for sms programming in j2me.
I don't have absolutely any idea regarding this.

Thanks
R.Naik

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

--------------------------------

Spam/Virus scanning by CanIt Pro

For more information see

http://www.kgbinternet.com/SpamFilter.htm

To control your spam filter, log in at

http://filter.kgbinternet.com

--- message truncated ---

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Ian Strain

here is a send sms midlet:

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;

public class SmsSend extends MIDlet implements CommandListener, Runnable {

private Display display;

private Form firstScreen;
private TextField phoneNumber;
private TextField messageText;
private TextField portNumber;
private ChoiceGroup binOrText;

private Command exitMIDlet;
private Command sendMessage;

private boolean sendBinary = false;

private static final int PORTNUMBER = 50000;

public SmsSend() {
exitMIDlet = new Command("Exit", Command.EXIT, 1);
sendMessage = new Command("Send message", Command.SCREEN, 1);

String[] elements = {"Text", "Binary"};
binOrText = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE, elements, null);

firstScreen = new Form("New message to be sent:");
phoneNumber = new TextField("number:",null,64,TextField.PHONENUMBER);
messageText = new TextField("message:",null,64,TextField.ANY);
portNumber = new TextField("port:",null,64,TextField.NUMERIC);
firstScreen.append(phoneNumber);
firstScreen.append(messageText);
firstScreen.append(portNumber);
firstScreen.append(binOrText);
firstScreen.addCommand(exitMIDlet);
firstScreen.addCommand(sendMessage);
firstScreen.setCommandListener(this);
}

protected void startApp() {
display = Display.getDisplay(this);
display.setCurrent(firstScreen);
}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable s) {

if (c == exitMIDlet) {
destroyApp(true);
notifyDestroyed();
return;
}

if(c == sendMessage){
if(binOrText.isSelected(0)) {
sendBinary = false;
} else {
sendBinary = true;
}

String number = phoneNumber.getString();
String text = messageText.getString();
String port = portNumber.getString();

Thread t = new Thread(this);
t.start();
}
}

public void run() {
String url;
MessageConnection connection = null;
TextMessage message = null;
BinaryMessage b_message = null;

String number = phoneNumber.getString();
String text = messageText.getString();
String port = portNumber.getString();

url = "sms://" + number + ":" + port;

if(!port.equals("")) {
try {
connection = (MessageConnection) Connector.open(url);
if(!sendBinary) {
message = (TextMessage)connection.newMessage(MessageConnection.TEXT_MESSAGE);
message.setPayloadText(text);
connection.send(message);
} else {
b_message =
(BinaryMessage)connection.newMessage(MessageConnection.BINARY_MESSAGE);
b_message.setPayloadData(text.getBytes());
connection.send(b_message);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(connection != null)
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}

and here is an sms receive midlet:

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import javax.wireless.messaging.*;

public class SmsReceive extends MIDlet implements CommandListener, Runnable {
MessageConnection connection;
String payload;
String url;
Form form;

private Display display;

private Form firstScreen;
private StringItem phoneNumber;
private StringItem messageText;
private StringItem portNum;
private TextField portNumber;

private Alert secondScreen;

private Command exitMIDlet;
Command back;

private static int PORTNUMBER = 50000;

public SmsReceive() {
exitMIDlet = new Command("Exit", Command.EXIT, 1);
back = new Command("Back", Command.BACK, 1);

firstScreen = new Form("New message received:");
phoneNumber = new StringItem("number:",null);
messageText = new StringItem("message:",null);
portNum = new StringItem("port:",null);
portNumber = new TextField("port:",null,64,TextField.NUMERIC);
firstScreen.append(phoneNumber);
firstScreen.append(messageText);
firstScreen.append(portNum);
firstScreen.addCommand(exitMIDlet);
firstScreen.addCommand(back);
firstScreen.setCommandListener(this);

secondScreen = new Alert("Alert"," New message!",null,AlertType.INFO);
secondScreen.setTimeout(Alert.FOREVER);
}

protected void startApp() {
display = Display.getDisplay(this);
form = new Form("Receive");
form.append(portNumber);
Command cmd = new Command("Enter", Command.OK, 1);
form.addCommand(cmd);
form.setCommandListener(this);
display.setCurrent(form);
}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable s) {
if(c.getLabel().equals("Enter")) {
if(!portNumber.getString().equals(" ")) {
try {
PORTNUMBER = Integer.parseInt(portNumber.getString());
} catch (NumberFormatException nfe) {
System.out.println("Exception: " + nfe);
}
}
url = "sms://"+":"+ PORTNUMBER;
portNum.setText("" + PORTNUMBER);

Thread t = new Thread(this);
t.start();
display.setCurrent(firstScreen);
}
if (c == exitMIDlet) {
destroyApp(true);
notifyDestroyed();
return;
}

if(c == back) {
display.setCurrent(form);
}
}

public void run() {
connection = null;
Message message;
TextMessage textMessage;
BinaryMessage binaryMessage;
String number;
String text;

try {
connection = (MessageConnection) Connector.open(url);
while(true) {
message = connection.receive();
number = message.getAddress();
phoneNumber.setText(number);
if(message instanceof TextMessage){
textMessage = (TextMessage)message;
text = textMessage.getPayloadText();
} else {
BinaryMessage binary = (BinaryMessage)message;
byte[] data = binary.getPayloadData();
text = new String(data, "UTF-8");
}
messageText.setText(text);
}
} catch (Exception e) {
e.printStackTrace();
try {
if(connection != null)
connection.close();
} catch(Exception e1) {
e1.printStackTrace();
}
return;
}
}
}

and here is an sms receive midlet using a MessageListener

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
import javax.wireless.messaging.*;

public class SmsReceiveListener extends MIDlet implements CommandListener,
Runnable, MessageListener {
MessageConnection connection;
String payload;
String url;
Form form;

private Display display;

private Form firstScreen;
private StringItem phoneNumber;
private StringItem messageText;
private StringItem portNum;
private TextField portNumber;

private Alert secondScreen;

private Command exitMIDlet;
Command back;

private static int PORTNUMBER = 50000;

public SmsReceiveListener() {
exitMIDlet = new Command("Exit", Command.EXIT, 1);
back = new Command("Back", Command.BACK, 1);

firstScreen = new Form("New message received:");
phoneNumber = new StringItem("number:",null);
messageText = new StringItem("message:",null);
portNum = new StringItem("port:",null);
portNumber = new TextField("port:",null,64,TextField.NUMERIC);
firstScreen.append(phoneNumber);
firstScreen.append(messageText);
firstScreen.append(portNum);
firstScreen.addCommand(exitMIDlet);
firstScreen.addCommand(back);
firstScreen.setCommandListener(this);

secondScreen = new Alert("Alert"," New message!",null,AlertType.INFO);
secondScreen.setTimeout(Alert.FOREVER);
}

protected void startApp() {
display = Display.getDisplay(this);
form = new Form("Receive");
form.append(portNumber);
Command cmd = new Command("Enter", Command.OK, 1);
form.addCommand(cmd);
form.setCommandListener(this);
display.setCurrent(form);
}

protected void destroyApp(boolean unconditional) {

}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable s) {
if(c.getLabel().equals("Enter")) {
if(!portNumber.getString().equals(" ")) {
try {
PORTNUMBER = Integer.parseInt(portNumber.getString());
} catch (NumberFormatException nfe) {
System.out.println("Exception: " + nfe);
}
}
url = "sms://"+":"+ PORTNUMBER;
portNum.setText("" + PORTNUMBER);

MessengerThread msg = new MessengerThread();
msg.start();

Thread t = new Thread(this);
t.start();
display.setCurrent(firstScreen);
}
if (c == exitMIDlet) {
destroyApp(true);
notifyDestroyed();
return;
}

if(c == back) {
display.setCurrent(form);
}
}

public void run() {
connection = null;
Message message;
TextMessage textMessage;
BinaryMessage binaryMessage;
String number;
String text;

try {
connection = (MessageConnection) Connector.open(url);
connection.setMessageListener(this);
} catch (Exception e) {
e.printStackTrace();
try {
if(connection != null)
connection.close();
} catch(Exception e1) {
e1.printStackTrace();
}
return;
}
}

public void notifyIncomingMessage(MessageConnection msgConn) {
MessengerThread t = new MessengerThread();
t.start();
}

private class MessengerThread extends Thread {
private Message msg;

public MessengerThread(Message msg) {
this.msg = msg;
}

public MessengerThread() {
this.msg = null;
}

public void run() {
String number;
try {
if (msg == null) {
Message msg = connection.receive();

number = msg.getAddress();
phoneNumber.setText(number);

if (msg instanceof BinaryMessage) {
BinaryMessage binary = (BinaryMessage)msg;
byte[] data = binary.getPayloadData();
payload = new String(data, "UTF-8");
} else if (msg instanceof TextMessage) {
TextMessage text = (TextMessage)msg;
payload = text.getPayloadText();
}
messageText.setText(payload);
} else {
connection.send(msg);
}
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage());
}
}
}
}

I just happen to be working on sms at the moment!!

Share the wealth!

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff KVM-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

mihai_preda
Offline
Joined: 2006-11-17
Points: 0