首页 arrow J2ME开发 arrow 新手上路 arrow J2ME发送短信息
J2ME发送短信息
Author Author: Wupei | Date Date: 2009-03-29 | View Count View: 2883 | Section & Category J2ME开发 - 新手上路 | Digg Digg: 3

在实际的开发中,用手机来发送短信,是很常见的做法!如,我们的产品出了问题,可以提示用户发送相关信息给我们,这对我开发来说是很有意义的事!其实,用J2ME来编写发送短信的代码是很容易的事!
步骤:
1,建立连接
2,设置短信息类型(文本或者二进制).
3,设置信息内容
4,发送

具体代买如下:

public class SendMessage {
    private String address = ""; //发送地址
    public SendMessage(String messageContent, String phoneNumber) {
        address = "sms://" + phoneNumner;
        sendMeassage(messageContent, phoneNumber);
    }
 
    public boolean sendMeassage(String content, String phoneNumber) {
        try {
            //建立连接
            MessageConnection conn = (MessageConnection) Connector.open(address);
            //设置短信息类型为文本
            TextMessage msg = (TextMessage) conn.newMessage(MessageConnection.
                    TEXT_MESSAGE);
            //设置信息内容
            msg.setPayloadText(content);
            //发送
            conn.send(msg);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}



 


更多阅读:

 
   评论 (1)
评论的 RSS
1
by: 挨踢 (注册会员) 2011-08-26 09:03
为什么phoneNumber这个参数没有用到
回复该评论

我要发表评论

登录菜单

最新文章

本月热门

订阅本站

RSS 0.91 RSS 1.0 RSS 2.0 ATOM 0.3 OPML