短信发送机的实现
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-02 06:20 点击:次
今天早上回来就产生了一个想法,不如用j2me实现一个短信发送机的程序,然后只需要填入几个数字就可以实现短信的自动发送等。
经过大概2个小时的奋斗,终于写好了,并且在多部不同品牌的机器运行良好,而且很实用,不过可以有些手机需要数字签名,否则的话,会不停的提示你。郁闷,不过索爱跟三星就可以设置。
现在公布源代码跟按照文件
先让大家看个图
经过大概2个小时的奋斗,终于写好了,并且在多部不同品牌的机器运行良好,而且很实用,不过可以有些手机需要数字签名,否则的话,会不停的提示你。郁闷,不过索爱跟三星就可以设置。
现在公布源代码跟按照文件
先让大家看个图
java 代码
/********************************************************************
* 项目名称 :j2me学习
/********************************************************************
* 项目名称 :j2me学习
*
* Copyright 2005-2006 Wuhua. All rights reserved
********************************************************************/
package org.fox.sms;
* Copyright 2005-2006 Wuhua. All rights reserved
********************************************************************/
package org.fox.sms;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;
/**
* 类名:SMSForm.java
* 类名:SMSForm.java
* 编写日期: 2007-5-25
* 程序功能描述:
* Demo:
* Bug:
*
* 程序变更日期 :
* 程序变更日期 :
* 变更作者 :
* 变更说明 :
*
* @author wuhua
rrq12345@163.com
*/
public class SMSForm extends Form
implements CommandListener, Runnable{
* @author wuhua
rrq12345@163.com
*/
public class SMSForm extends Form
implements CommandListener, Runnable{
Command send = new Command("发送", Command.OK, 1);
Command back = new Command("返回", Command.BACK, Command.BACK);
TextField phone;
TextField content;
TextField num;
TextField timeOut;
TextField text;
String serverPort = "5000";// getAppProperty("serverPort");
int sms;
Command back = new Command("返回", Command.BACK, Command.BACK);
TextField phone;
TextField content;
TextField num;
TextField timeOut;
TextField text;
String serverPort = "5000";// getAppProperty("serverPort");
int sms;
Menu menu;
public SMSForm(Menu m) {
super("短信发送机");
public SMSForm(Menu m) {
super("短信发送机");
setCommandListener(this);
text = new TextField("状态", "等待发送短信", 20, TextField.ANY);
phone = new TextField("号码", "xxxxxx:", 20, TextField.NUMERIC);
content = new TextField("指令", "777", 10, TextField.NUMERIC);
num = new TextField("条数", "23", 10, TextField.NUMERIC);
timeOut = new TextField("时间格", "10", 10, TextField.NUMERIC);
this.append(phone);
this.append(content);
this.append(num);
this.append(timeOut);
this.append(text);
this.addCommand(send);
this.addCommand(back);
this.menu = m;
text = new TextField("状态", "等待发送短信", 20, TextField.ANY);
phone = new TextField("号码", "xxxxxx:", 20, TextField.NUMERIC);
content = new TextField("指令", "777", 10, TextField.NUMERIC);
num = new TextField("条数", "23", 10, TextField.NUMERIC);
timeOut = new TextField("时间格", "10", 10, TextField.NUMERIC);
this.append(phone);
this.append(content);
this.append(num);
this.append(timeOut);
this.append(text);
this.addCommand(send);
this.addCommand(back);
this.menu = m;
}
public void commandAction(Command c, Displayable arg1) {
if(c == send){
new Thread(this).start();
this.removeCommand(send);
}else{
SMSSenderMIDlet.display.setCurrent(menu);
}
if(c == send){
new Thread(this).start();
this.removeCommand(send);
}else{
SMSSenderMIDlet.display.setCurrent(menu);
}
}
public void run() {
int num = Integer.parseInt(this.num.getString());
int sleep = Integer.parseInt(this.timeOut.getString());
while(true){
//System.out.println(sleep);
if(sms < num){
senderImpl();
}
else{
int num = Integer.parseInt(this.num.getString());
int sleep = Integer.parseInt(this.timeOut.getString());
while(true){
//System.out.println(sleep);
if(sms < num){
senderImpl();
}
else{
SMSSenderMIDlet.display.setCurrent(menu);
break;
}
try {
//System.out.println(sleep);
Thread.sleep(sleep*1000);
//System.out.println(sleep);
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
}
try {
//System.out.println(sleep);
Thread.sleep(sleep*1000);
//System.out.println(sleep);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void senderImpl() {
String addr = "sms://" + phone.getString();
System.out.println("发送地址为:" + addr);
MessageConnection conn;
try {
conn = (MessageConnection) Connector.open(addr);
TextMessage msg = (TextMessage) conn
.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(content.getString());
conn.send(msg);
conn.close();
sms++;
//text = sms+"";
text.setString("成功发送" +this.num.getString() + "第" + sms + "条");
String addr = "sms://" + phone.getString();
System.out.println("发送地址为:" + addr);
MessageConnection conn;
try {
conn = (MessageConnection) Connector.open(addr);
TextMessage msg = (TextMessage) conn
.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setPayloadText(content.getString());
conn.send(msg);
conn.close();
sms++;
//text = sms+"";
text.setString("成功发送" +this.num.getString() + "第" + sms + "条");
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
/********************************************************************
* 项目名称 :j2me学
* 项目名称 :j2me学
相关新闻>>
- 发表评论
-
- 最新评论 更多>>