发短消息的程序
来源:互联网 发布:淘宝snp旗舰店是正品吗 编辑:程序博客网 时间:2024/04/30 11:54
下面的程序是用来发短信的,本人用它给自己的手机发了三条,结果只是发出去,没有收到,倒是扣了2.4元,平均每条短信0.8元。
目前还不知道是什么原因,自己再研究研究吧,你如果知道一定要告诉我哦。
public class MailSender extends MIDlet implements CommandListener{
private Display display;
private Form form;
private TextField messageTo;
private TextField content;
private Command exit;
private Command send;
private Alert alert;
public MailSender(){
display = Display.getDisplay(this);
form = new Form("My Message Sender");
messageTo = new TextField("PhoneNumber:","",1513,TextField.NUMERIC);
content = new TextField("Content:","",50,TextField.ANY);
exit = new Command("Exit",Command.EXIT,1);
send = new Command("Send",Command.OK,2);
form.append(messageTo);
form.append(content);
form.addCommand(exit);
form.addCommand(send);
form.setCommandListener(this);
}
public void startApp() {
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if(c == send){
boolean result = SMSUtil.sendMessage(messageTo.getString(),content.getString());
if(result){
alert = new Alert("Notice","Send OK!",null, AlertType.INFO);
}
else{
alert = new Alert("Notice","Send Failed!",null, AlertType.INFO);
}
display.setCurrent(alert);
}
else if(c == exit){
destroyApp(true);
notifyDestroyed();
}
}
}
public class SMSUtil {
/**
* 给指定号码发送短信息
* @param phoneNumber 手机号码
* @param content 短信息内容
* @return 发送成功返回true,否则返回false
*/
public static boolean sendMessage(String phoneNumber,String content){
//返回值
boolean result = true;
try{
//地址
String address = "sms://+" + phoneNumber;
//建立连接
MessageConnection conn = (MessageConnection)Connector.open(address);
//设置短信息类型为文本,短信息有文本和二进制两种类型
TextMessage msg = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
//设置信息内容
msg.setPayloadText(content);
//发送
conn.send(msg);
}catch(Exception e){
result = false;
}
return result;
}
}
- 发短消息的程序
- 简单的手机发短消息工具类:SMSSender.java
- 在线短消息收发的程序,不用数据库
- Android发送短消息程序的总结
- 向Android模拟器打电话和发短消息
- 短消息系统的调整
- 手机的短消息实现
- 发给父母的“短消息”
- 短消息的暴利时代
- Android开发里面怎么在画图的时候监测到一个特定的数值利用Intent调用发短消息啊
- 短消息
- 发邮件的JAVA程序
- 发一个截图的程序
- 在公司实习时做的短消息提醒模块部分程序
- VB实现在PC上通过手机发短消息
- 不同机型中使用j2me调出拨号和发短消息
- 暖暖的短消息(集锦)
- 下一代社区短消息的变化
- 在你还在犹豫要学哪一门语言的时候,人家早就开始说不定已经学到一定层次了。
- 注意出错信息 不要偷懒 有果必有因
- linux命令行(一)
- 12.25 OSGeo讲座关键词
- 如何在Windows平台搭建完整的OpenGL开发环境?
- 发短消息的程序
- 《网页设计与欣赏》大学选修课论文
- 我的异常网-myexception,2009-12-25
- 我的异常网-myexception,2009-12-25
- 关于委托机制的经典好文
- 超市管理系统
- C指针
- vc 对话框程序控件提示功能
- Linux操作系统定时调度系统Cron介绍