dr_jacky_2005
پنج شنبه 28 بهمن 1389, 11:53 صبح
سلام.
من کد این مثال معروف ارسال و دریافت اس ام اس رو میذارم اینجا.
سوالم اینه که چطوری براش یک لطفا صبر کنید خوشگل بزارم ، اوون قسمتی از کد که منتظر دریافت اس ام اس است؟!
کد:
// WMAExample.java version 2.1
// Copyright 2004 Nokia Corporation.
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUP. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Corporation
// retains the right to make changes to this source code at any time,
// without notice. This source code is provided for informational
// purposes only.
//
// Nokia and Nokia Connecting People are registered trademarks of Nokia
// Corporation. Java and all Java-based marks are trademarks or registered
// trademarks of Sun Microsystems, Inc. Other product and company names
// mentioned herein may be trademarks or trade names of their respective owners.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.
//
/**
* Change History:
* -----------------------------------------------------------------------------
* 2.1
* Updated the MIDlet to send to port 7500 and register the listener in the
* jad file.
* Added MIDlet icon <N.png> to the MIDlet package.
* -----------------------------------------------------------------------------
* 2.0
* Updated to run on MIDP 2.0 implementations.
* Redesign of MIDlet UI.
* -----------------------------------------------------------------------------
* 1.0 First implementation.
* -----------------------------------------------------------------------------
*/
import java.io.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class WMAExample extends MIDlet implements CommandListener, MessageListener, ItemStateListener {
/**
* This command exits the midlet.
*/
private Command exitCommand;
/**
* This command sends a message.
*/
private Command sendCommand;
/**
* This is the default display.
*/
private Display display;
/**
* This is the main form.
*/
private Form form;
/**
* This is the choicegroup for which we decide whether to send
* text or binary SMS messages.
*/
private ChoiceGroup cg;
/**
* This is the Textfield containing the destination phone number.
*/
private TextField MessageAddressField;
/**
* This is the Textfield containing the message body.
*/
private TextField TextMessageBodyField;
/**
* This is the String displayed when set to send a Binary Message.
*/
private StringItem binaryFormText;
/**
* This is the connection for sending messages.
*/
private MessageConnection con;
/**
* Alert that is displayed when a message is sent.
*/
private Alert alert;
/**
* Image to display in the Alert.
*/
private Image thumbUp;
private String MessageAddress;
private String MessageServerPort;
private String TextMessageBody;
private String BinaryMessageBodyFile;
private byte[] BinaryMessageBody;
private void log (String logMessage) {
System.out.println (logMessage);
if (form != null) {
form.append(logMessage);
}
}
private void init () {
// Initialize the address, where the message will be sent to
MessageAddress = getAppProperty (MIDletMessageAddressAttribute);
if (MessageAddress == null) {
MessageAddress = DefaultMIDletMessageAddress;
}
// Initialize the port number, where the MIDlet is listening on.
MessageServerPort = getAppProperty (MIDletServerPortAttribute);
if (MessageServerPort == null) {
MessageServerPort = DefaultMIDletServerPort;
}
// Initialize the message to send
// The message can be either a text message or a binary message
TextMessageBody = getAppProperty (MIDletMessageTextBodyAttribute);
BinaryMessageBodyFile = getAppProperty (MIDletBinaryMessageBodyFileAttribute);
// If there is no message defined in the JAD file, send a text message
if ((TextMessageBody == null) && (BinaryMessageBodyFile == null)) {
TextMessageBody = DefaultMIDletTextMessage;
}
// Read the binary file from the JAR
if (BinaryMessageBodyFile != null) {
log ("Reading resource file: " + BinaryMessageBodyFile);
try
{
InputStream is = getClass().getResourceAsStream(BinaryMessageBodyFi le);
if (is == null ) {
// The file name in the JAD file is mistyped or
// the file is not included in the JAR
log ("Resource file " + BinaryMessageBodyFile +
" not found in the JAR file.");
// We do not have a binary message
BinaryMessageBodyFile = null;
} else {
DataInputStream dataStream = new DataInputStream(is);
byte[] tempBuffer = new byte [500];
byte[] data = new byte[1];
int size = 0;
int byteRead = dataStream.read(data, 0, data.length);
while(byteRead >= 0)
{
tempBuffer[size++] = data[0];
byteRead = dataStream.read(data, 0, data.length);
}
dataStream.close();
if (size >0 )
{
BinaryMessageBody = new byte [size];
}
for (int i=0; i<size; i++)
{
BinaryMessageBody[i] = tempBuffer [i];
}
}
} catch(Exception ex)
{
log ("Exception: " + ex.toString());
}
}
}
/** Constructor */
public WMAExample() {
}
/** Main method */
public void startApp() {
// Initialize MIDlet parameters from the JAD file
init ();
// Listen for incomming messages
listen (MessageServerPort);
// Create the commands
exitCommand = new Command("Exit", Command.EXIT, 2);
sendCommand = new Command("Send", Command.OK, 1);
// Create the UI
form = new Form("WMAExample");
//create the choicegroup & add it to the form.
cg = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE);
cg.append("Text",null);
cg.append("Binary",null);
form.append(cg);
//register the itemStateChanged listener.
form.setItemStateListener(this);
// Create a field for the destination address
MessageAddressField = new TextField("Address:", MessageAddress, 20, TextField.PHONENUMBER);
form.append(MessageAddressField);
// Create a field for the message body
TextMessageBodyField = new TextField("Message:", TextMessageBody, 435, TextField.ANY);
form.append(TextMessageBodyField);
// Add commands to the form
form.addCommand(exitCommand);
form.addCommand(sendCommand);
form.setCommandListener(this);
// Set display
display = Display.getDisplay(this);
display.setCurrent(form);
}
/** Handle pausing the MIDlet */
public void pauseApp() {
try
{
con.close();
}
catch (Exception ex)
{
}
}
/** Handle destroying the MIDlet */
public void destroyApp(boolean unconditional) {
try
{
con.close();
}
catch (Exception ex)
{
}
}
public void notifyIncomingMessage(MessageConnection mscon) {
if (con == mscon) {
try {
//TextMessage receivedMessage = (TextMessage)mscon.receive();
Message receivedMessage = mscon.receive();
if (receivedMessage instanceof TextMessage) {
messageReceivedHandler( (TextMessage) receivedMessage);
}
if (receivedMessage instanceof BinaryMessage) {
messageReceivedHandler( (BinaryMessage) receivedMessage);
}
}
catch (Exception ex) {
log("Exception: " + ex.toString());
}
}
}
/**
* This method responds to the selected command.
*
* @param c The command that triggered this event
* @param d The displayable upon which the command that triggered the
* event is placed
*/
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
// Send a text message
if (c == sendCommand && cg.getSelectedIndex() == 0) {
if (TextMessageBody != null) {
String destAddress = MessageAddressField.getString();
String messageBody = TextMessageBodyField.getString();
sendTextMessage(con, destAddress, messageBody);
}
}
// Send a binary message
else if (c == sendCommand && cg.getSelectedIndex() == 1) {
if (BinaryMessageBodyFile != null) {
String destAddress = MessageAddressField.getString();
sendBinaryMessage(con, destAddress, BinaryMessageBody);
}
}
}
/**
* Detects when the ChoiceGroup value is changed and removes TextMessageField
* from the form and adds binaryFormText in it's place, and visa versa.
* */
public void itemStateChanged(Item item) {
int i; //to use in the search loop
//test whether the item that changed is the ChoiceGroup, else exit.
if(item.equals(cg)){
//if BinaryMessaging selected
if (cg.getSelectedIndex() == 1) {
//search for the TextMessageField Object and then remove it from the form.
//add binaryFormText to the form in its place.
for (i = 0; i < form.size(); ++i) {
if(form.get(i) == TextMessageBodyField) {
form.delete(i);
binaryFormText = new StringItem("Message:","Ready to send /test.bin");
form.append(binaryFormText);
break;
}
}
}
//add the TextMessageBodyField & remove binaryFormText
else if (cg.getSelectedIndex() == 0) {
//first search for and remove the string "str".
for(i=0; i<form.size(); ++i){
if(form.get(i) == binaryFormText){
form.delete(i);
form.append(TextMessageBodyField);
}
}
}//end else if
}//end if(item.equals(cg))
}
public void sendBinaryMessage
(MessageConnection connection, String destAddress, byte[] Body) {
// Construct the message
BinaryMessage Message = (BinaryMessage)connection.newMessage(
MessageConnection.BINARY_MESSAGE,
"sms://" + destAddress + ":7500");
// Set the payload
Message.setPayloadData(Body);
try
{
// Send the message
connection.send(Message);
thumbUp = Image.createImage("/thumbsup.png");
alert = new Alert("Message Sent",
"Binary Message sent: " + Body.length + " bytes.",
thumbUp, AlertType.CONFIRMATION);
alert.setTimeout(3000); //3 seconds
display.setCurrent(alert,form);
//log ("Binary Message sent: " + Body.length + " bytes.");
}
catch (IOException ioex)
{
log("IOException: " + ioex.toString());
}
catch(SecurityException syex)
{
log("SecurityException: " + syex.toString());
}
catch (Exception ex)
{
log("Exception: " + ex.toString());
}
}
public void sendTextMessage
(MessageConnection connection, String destAddress, String Body) {
// Construct the message
TextMessage Message = (TextMessage)connection.newMessage(
MessageConnection.TEXT_MESSAGE,
"sms://" + destAddress +":7500");
// Set the payload
Message.setPayloadText(Body);
try
{
// Send the message
connection.send(Message);
thumbUp = Image.createImage("/thumbsup.png");
alert = new Alert("Message Sent",
"Text Message sent: " + Body,
thumbUp, AlertType.CONFIRMATION);
alert.setTimeout(3000); //3 seconds
display.setCurrent(alert, form);
//log ("Text Message sent: " + Body);
}
catch (IOException ioex)
{
log("IOException: " + ioex.toString());
}
catch(SecurityException syex)
{
log("SecurityException: " + syex.toString());
}
catch (Exception ex)
{
log("Exception: " + ex.toString());
}
}
public void messageReceivedHandler (TextMessage receivedMessage) {
String senderAddress = receivedMessage.getAddress();
String receivedMessageBody = receivedMessage.getPayloadText();
log ("Text Message received: " + receivedMessageBody);
}
public void messageReceivedHandler (BinaryMessage receivedMessage) {
String senderAddress = receivedMessage.getAddress();
byte[] receivedMessageBody = receivedMessage.getPayloadData();
log ("Binary Message received: " + receivedMessageBody.length + " bytes.");
}
public void listen (String MessageServerPort) {
try
{
con = (MessageConnection) Connector.open(
"sms://:" + MessageServerPort);
con.setMessageListener(this);
}
catch(Exception ex)
{
log("Exception during listen: " + ex.toString());
}
}
/* Default values, if there is nothing specified in the JAD file */
private static final String DefaultMIDletMessageAddress = "3300001:7500";
private static final String DefaultMIDletServerPort = "7500";
private static final String DefaultMIDletTextMessage = "Test message";
/* Constants */
private static final String MIDletMessageAddressAttribute =
new String ("Message-Address");
private static final String MIDletServerPortAttribute =
new String ("ServerPort");
private static final String MIDletMessageTextBodyAttribute =
new String ("Message-Text-Body");
private static final String MIDletBinaryMessageBodyFileAttribute =
new String ("Binary-Message-Body-File");
}
میدونم که برنامه که run بشه،دائم داره listen میکنه به پورت که اس اومد،داد و بیداد کنه.
ولی من هدفم اینه که وقتی دگمۀ ارسال اس ام اس رو زد،لطفا منتظر بیایید،بیاد.
(یعنی اینکه در موارد دیگر که ارسال رو نزده ولی یکی روو اوون پورت خاص اس ام اس داد،موردی نداره که صaiting باشه یا نه )
من کد این مثال معروف ارسال و دریافت اس ام اس رو میذارم اینجا.
سوالم اینه که چطوری براش یک لطفا صبر کنید خوشگل بزارم ، اوون قسمتی از کد که منتظر دریافت اس ام اس است؟!
کد:
// WMAExample.java version 2.1
// Copyright 2004 Nokia Corporation.
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUP. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Corporation
// retains the right to make changes to this source code at any time,
// without notice. This source code is provided for informational
// purposes only.
//
// Nokia and Nokia Connecting People are registered trademarks of Nokia
// Corporation. Java and all Java-based marks are trademarks or registered
// trademarks of Sun Microsystems, Inc. Other product and company names
// mentioned herein may be trademarks or trade names of their respective owners.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.
//
/**
* Change History:
* -----------------------------------------------------------------------------
* 2.1
* Updated the MIDlet to send to port 7500 and register the listener in the
* jad file.
* Added MIDlet icon <N.png> to the MIDlet package.
* -----------------------------------------------------------------------------
* 2.0
* Updated to run on MIDP 2.0 implementations.
* Redesign of MIDlet UI.
* -----------------------------------------------------------------------------
* 1.0 First implementation.
* -----------------------------------------------------------------------------
*/
import java.io.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class WMAExample extends MIDlet implements CommandListener, MessageListener, ItemStateListener {
/**
* This command exits the midlet.
*/
private Command exitCommand;
/**
* This command sends a message.
*/
private Command sendCommand;
/**
* This is the default display.
*/
private Display display;
/**
* This is the main form.
*/
private Form form;
/**
* This is the choicegroup for which we decide whether to send
* text or binary SMS messages.
*/
private ChoiceGroup cg;
/**
* This is the Textfield containing the destination phone number.
*/
private TextField MessageAddressField;
/**
* This is the Textfield containing the message body.
*/
private TextField TextMessageBodyField;
/**
* This is the String displayed when set to send a Binary Message.
*/
private StringItem binaryFormText;
/**
* This is the connection for sending messages.
*/
private MessageConnection con;
/**
* Alert that is displayed when a message is sent.
*/
private Alert alert;
/**
* Image to display in the Alert.
*/
private Image thumbUp;
private String MessageAddress;
private String MessageServerPort;
private String TextMessageBody;
private String BinaryMessageBodyFile;
private byte[] BinaryMessageBody;
private void log (String logMessage) {
System.out.println (logMessage);
if (form != null) {
form.append(logMessage);
}
}
private void init () {
// Initialize the address, where the message will be sent to
MessageAddress = getAppProperty (MIDletMessageAddressAttribute);
if (MessageAddress == null) {
MessageAddress = DefaultMIDletMessageAddress;
}
// Initialize the port number, where the MIDlet is listening on.
MessageServerPort = getAppProperty (MIDletServerPortAttribute);
if (MessageServerPort == null) {
MessageServerPort = DefaultMIDletServerPort;
}
// Initialize the message to send
// The message can be either a text message or a binary message
TextMessageBody = getAppProperty (MIDletMessageTextBodyAttribute);
BinaryMessageBodyFile = getAppProperty (MIDletBinaryMessageBodyFileAttribute);
// If there is no message defined in the JAD file, send a text message
if ((TextMessageBody == null) && (BinaryMessageBodyFile == null)) {
TextMessageBody = DefaultMIDletTextMessage;
}
// Read the binary file from the JAR
if (BinaryMessageBodyFile != null) {
log ("Reading resource file: " + BinaryMessageBodyFile);
try
{
InputStream is = getClass().getResourceAsStream(BinaryMessageBodyFi le);
if (is == null ) {
// The file name in the JAD file is mistyped or
// the file is not included in the JAR
log ("Resource file " + BinaryMessageBodyFile +
" not found in the JAR file.");
// We do not have a binary message
BinaryMessageBodyFile = null;
} else {
DataInputStream dataStream = new DataInputStream(is);
byte[] tempBuffer = new byte [500];
byte[] data = new byte[1];
int size = 0;
int byteRead = dataStream.read(data, 0, data.length);
while(byteRead >= 0)
{
tempBuffer[size++] = data[0];
byteRead = dataStream.read(data, 0, data.length);
}
dataStream.close();
if (size >0 )
{
BinaryMessageBody = new byte [size];
}
for (int i=0; i<size; i++)
{
BinaryMessageBody[i] = tempBuffer [i];
}
}
} catch(Exception ex)
{
log ("Exception: " + ex.toString());
}
}
}
/** Constructor */
public WMAExample() {
}
/** Main method */
public void startApp() {
// Initialize MIDlet parameters from the JAD file
init ();
// Listen for incomming messages
listen (MessageServerPort);
// Create the commands
exitCommand = new Command("Exit", Command.EXIT, 2);
sendCommand = new Command("Send", Command.OK, 1);
// Create the UI
form = new Form("WMAExample");
//create the choicegroup & add it to the form.
cg = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE);
cg.append("Text",null);
cg.append("Binary",null);
form.append(cg);
//register the itemStateChanged listener.
form.setItemStateListener(this);
// Create a field for the destination address
MessageAddressField = new TextField("Address:", MessageAddress, 20, TextField.PHONENUMBER);
form.append(MessageAddressField);
// Create a field for the message body
TextMessageBodyField = new TextField("Message:", TextMessageBody, 435, TextField.ANY);
form.append(TextMessageBodyField);
// Add commands to the form
form.addCommand(exitCommand);
form.addCommand(sendCommand);
form.setCommandListener(this);
// Set display
display = Display.getDisplay(this);
display.setCurrent(form);
}
/** Handle pausing the MIDlet */
public void pauseApp() {
try
{
con.close();
}
catch (Exception ex)
{
}
}
/** Handle destroying the MIDlet */
public void destroyApp(boolean unconditional) {
try
{
con.close();
}
catch (Exception ex)
{
}
}
public void notifyIncomingMessage(MessageConnection mscon) {
if (con == mscon) {
try {
//TextMessage receivedMessage = (TextMessage)mscon.receive();
Message receivedMessage = mscon.receive();
if (receivedMessage instanceof TextMessage) {
messageReceivedHandler( (TextMessage) receivedMessage);
}
if (receivedMessage instanceof BinaryMessage) {
messageReceivedHandler( (BinaryMessage) receivedMessage);
}
}
catch (Exception ex) {
log("Exception: " + ex.toString());
}
}
}
/**
* This method responds to the selected command.
*
* @param c The command that triggered this event
* @param d The displayable upon which the command that triggered the
* event is placed
*/
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
// Send a text message
if (c == sendCommand && cg.getSelectedIndex() == 0) {
if (TextMessageBody != null) {
String destAddress = MessageAddressField.getString();
String messageBody = TextMessageBodyField.getString();
sendTextMessage(con, destAddress, messageBody);
}
}
// Send a binary message
else if (c == sendCommand && cg.getSelectedIndex() == 1) {
if (BinaryMessageBodyFile != null) {
String destAddress = MessageAddressField.getString();
sendBinaryMessage(con, destAddress, BinaryMessageBody);
}
}
}
/**
* Detects when the ChoiceGroup value is changed and removes TextMessageField
* from the form and adds binaryFormText in it's place, and visa versa.
* */
public void itemStateChanged(Item item) {
int i; //to use in the search loop
//test whether the item that changed is the ChoiceGroup, else exit.
if(item.equals(cg)){
//if BinaryMessaging selected
if (cg.getSelectedIndex() == 1) {
//search for the TextMessageField Object and then remove it from the form.
//add binaryFormText to the form in its place.
for (i = 0; i < form.size(); ++i) {
if(form.get(i) == TextMessageBodyField) {
form.delete(i);
binaryFormText = new StringItem("Message:","Ready to send /test.bin");
form.append(binaryFormText);
break;
}
}
}
//add the TextMessageBodyField & remove binaryFormText
else if (cg.getSelectedIndex() == 0) {
//first search for and remove the string "str".
for(i=0; i<form.size(); ++i){
if(form.get(i) == binaryFormText){
form.delete(i);
form.append(TextMessageBodyField);
}
}
}//end else if
}//end if(item.equals(cg))
}
public void sendBinaryMessage
(MessageConnection connection, String destAddress, byte[] Body) {
// Construct the message
BinaryMessage Message = (BinaryMessage)connection.newMessage(
MessageConnection.BINARY_MESSAGE,
"sms://" + destAddress + ":7500");
// Set the payload
Message.setPayloadData(Body);
try
{
// Send the message
connection.send(Message);
thumbUp = Image.createImage("/thumbsup.png");
alert = new Alert("Message Sent",
"Binary Message sent: " + Body.length + " bytes.",
thumbUp, AlertType.CONFIRMATION);
alert.setTimeout(3000); //3 seconds
display.setCurrent(alert,form);
//log ("Binary Message sent: " + Body.length + " bytes.");
}
catch (IOException ioex)
{
log("IOException: " + ioex.toString());
}
catch(SecurityException syex)
{
log("SecurityException: " + syex.toString());
}
catch (Exception ex)
{
log("Exception: " + ex.toString());
}
}
public void sendTextMessage
(MessageConnection connection, String destAddress, String Body) {
// Construct the message
TextMessage Message = (TextMessage)connection.newMessage(
MessageConnection.TEXT_MESSAGE,
"sms://" + destAddress +":7500");
// Set the payload
Message.setPayloadText(Body);
try
{
// Send the message
connection.send(Message);
thumbUp = Image.createImage("/thumbsup.png");
alert = new Alert("Message Sent",
"Text Message sent: " + Body,
thumbUp, AlertType.CONFIRMATION);
alert.setTimeout(3000); //3 seconds
display.setCurrent(alert, form);
//log ("Text Message sent: " + Body);
}
catch (IOException ioex)
{
log("IOException: " + ioex.toString());
}
catch(SecurityException syex)
{
log("SecurityException: " + syex.toString());
}
catch (Exception ex)
{
log("Exception: " + ex.toString());
}
}
public void messageReceivedHandler (TextMessage receivedMessage) {
String senderAddress = receivedMessage.getAddress();
String receivedMessageBody = receivedMessage.getPayloadText();
log ("Text Message received: " + receivedMessageBody);
}
public void messageReceivedHandler (BinaryMessage receivedMessage) {
String senderAddress = receivedMessage.getAddress();
byte[] receivedMessageBody = receivedMessage.getPayloadData();
log ("Binary Message received: " + receivedMessageBody.length + " bytes.");
}
public void listen (String MessageServerPort) {
try
{
con = (MessageConnection) Connector.open(
"sms://:" + MessageServerPort);
con.setMessageListener(this);
}
catch(Exception ex)
{
log("Exception during listen: " + ex.toString());
}
}
/* Default values, if there is nothing specified in the JAD file */
private static final String DefaultMIDletMessageAddress = "3300001:7500";
private static final String DefaultMIDletServerPort = "7500";
private static final String DefaultMIDletTextMessage = "Test message";
/* Constants */
private static final String MIDletMessageAddressAttribute =
new String ("Message-Address");
private static final String MIDletServerPortAttribute =
new String ("ServerPort");
private static final String MIDletMessageTextBodyAttribute =
new String ("Message-Text-Body");
private static final String MIDletBinaryMessageBodyFileAttribute =
new String ("Binary-Message-Body-File");
}
میدونم که برنامه که run بشه،دائم داره listen میکنه به پورت که اس اومد،داد و بیداد کنه.
ولی من هدفم اینه که وقتی دگمۀ ارسال اس ام اس رو زد،لطفا منتظر بیایید،بیاد.
(یعنی اینکه در موارد دیگر که ارسال رو نزده ولی یکی روو اوون پورت خاص اس ام اس داد،موردی نداره که صaiting باشه یا نه )