here is aprogram for doing it in the mobile to mobile

SMSSender .java

import  javax.microedition.io. * ;
import  javax.microedition.lcdui. * ;
import  javax.wireless.messaging. * ;
import  java.io.IOException;

public   class  SMSSender 
implements  CommandListener, Runnable  {

/** user interface command for indicating Send request */
Command sendCommand 
= new Command("Send", Command.OK, 1);
/** user interface command for going back to the previous screen */
Command backCommand 
= new Command("Back", Command.BACK, 2);
/** Display to use. */
Display display;
/** The port on which we send SMS messages */
String smsPort;
/** The URL to send the message to */
String destinationAddress;
/** Area where the user enters a message to send */
TextBox messageBox;
/** Where to return if the user hits "Back" */
Displayable backScreen;
/** Displayed when a message is being sent */
Displayable sendingScreen;

/**
* Initialize the MIDlet with the current display object and
* graphical components. 
*/

public SMSSender(String smsPort, Display display,
Displayable backScreen, Displayable sendingScreen) 
{
this.smsPort = smsPort;
this.display = display;
this.destinationAddress = null;
this.backScreen = backScreen;
this.sendingScreen = sendingScreen;

messageBox 
= new TextBox("Enter Message"null65535, TextField.ANY);
messageBox.addCommand(backCommand);
messageBox.addCommand(sendCommand);
messageBox.setCommandListener(
this);
}


/**
* Prompt for message and send it
*/

public void promptAndSend(String destinationAddress)
{
this.destinationAddress = destinationAddress;
display.setCurrent(messageBox);
}


/**
* Respond to commands, including exit
@param c user interface command requested
@param s screen object initiating the request
*/

public void commandAction(Command c, Displayable s) {
try {
if (c == backCommand) {
display.setCurrent(backScreen);
}
 else if (c == sendCommand) {
display.setCurrent(sendingScreen);
new Thread(this).start(); 
}

}
 catch (Exception ex) {
ex.printStackTrace();
}

}


/**
* Send the message. Called on a separate thread so we don't have
* contention for the display
*/

public void run() {
String address 
= destinationAddress + ":" + smsPort;

MessageConnection smsconn 
= null;
try {
/** Open the message connection. */
smsconn 
= (MessageConnection)Connector.open(address);

TextMessage txtmessage 
= (TextMessage)smsconn.newMessage(
MessageConnection.TEXT_MESSAGE);
txtmessage.setAddress(address);
txtmessage.setPayloadText(messageBox.getString());
smsconn.send(txtmessage);
}
 catch (Throwable t) {
System.out.println(
"Send caught: ");
t.printStackTrace();
}

if (smsconn != null{
try {
smsconn.close();
}
 catch (IOException ioe) {
System.out.println(
"Closing connection caught: ");
ioe.printStackTrace();
}
 
}

}

}




interface


SMSSend.java

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

import  java.io.IOException;

/**
* An example MIDlet to send text via an SMS MessageConnection
*/

public   class  SMSSend  extends  MIDlet 
implements  CommandListener  {

/** user interface command for indicating Exit request. */
Command exitCommand 
= new Command("Exit", Command.EXIT, 2);
/** user interface command for proceeding to the next screen */
Command okCommand 
= new Command("OK", Command.OK, 1);
/** current display. */
Display display;
/** The port on which we send SMS messages */
String smsPort;
/** Area where the user enters the phone number to send the message to */
TextBox destinationAddressBox;
/** Error message displayed when an invalid phone number is entered */
Alert errorMessageAlert;
/** Alert that is displayed when a message is being sent */
Alert sendingMessageAlert;
/** Prompts for and sends the text message */
SMSSender sender;
/** The last visible screen when we paused */ 
Displayable resumeScreen 
= null;

/**
* Initialize the MIDlet with the current display object and
* graphical components. 
*/

public SMSSend() {
smsPort 
= getAppProperty("SMS-Port");

display 
= Display.getDisplay(this);

destinationAddressBox 
= new TextBox("Destination Address?"
null256, TextField.PHONENUMBER);
destinationAddressBox.addCommand(exitCommand);
destinationAddressBox.addCommand(okCommand);
destinationAddressBox.setCommandListener(
this);

errorMessageAlert 
= new Alert("SMS"nullnull, AlertType.ERROR);
errorMessageAlert.setTimeout(
5000);

sendingMessageAlert 
= new Alert("SMS"nullnull, AlertType.INFO);
sendingMessageAlert.setTimeout(
5000);
sendingMessageAlert.setCommandListener(
this);

sender 
= new SMSSender(smsPort, display, destinationAddressBox, 
sendingMessageAlert);

resumeScreen 
= destinationAddressBox;
}


/**
* startApp should return immediately to keep the dispatcher
* from hanging.
*/

public void startApp() {
display.setCurrent(resumeScreen);
}


/**
* Remember what screen is showing
*/

public void pauseApp() {
resumeScreen 
= display.getCurrent();
}


/**
* Destroy must cleanup everything.
@param unconditional true if a forced shutdown was requested
*/

public void destroyApp(boolean unconditional) {
}


/**
* Respond to commands, including exit
@param c user interface command requested
@param s screen object initiating the request
*/

public void commandAction(Command c, Displayable s) {
try {
if (c == exitCommand || c == Alert.DISMISS_COMMAND) {
destroyApp(
false);
notifyDestroyed();
}
 else if (c == okCommand) {
promptAndSend();
}

}
 catch (Exception ex) {
ex.printStackTrace();
}

}


/**
* Prompt for and send the message
*/

private void promptAndSend() {
String address 
= destinationAddressBox.getString();
if (!SMSSend.isValidPhoneNumber(address)) {
errorMessageAlert.setString(
"Invalid phone number");
display.setCurrent(errorMessageAlert, destinationAddressBox);
return;
}

String statusMessage 
= "Sending message to " + address + "...";
sendingMessageAlert.setString(statusMessage);
sender.promptAndSend(
"sms://" + address);
}


/**
* Check the phone number for validity
* Valid phone numbers contain only the digits 0 thru 9, and may contain 
* a leading '+'.
*/

private static boolean isValidPhoneNumber(String number) {
char[] chars = number.toCharArray();
if (chars.length == 0{
return false;
}

int startPos = 0;
// initial '+' is OK
if (chars[0== '+'{
startPos 
= 1;
}

for (int i = startPos; i < chars.length; ++i) {
if (!Character.isDigit(chars)) {
return false;
}

}

return true;
}

}
 
 
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值