使用J2ME傳送簡訊

來源:互聯網
上載者:User
以下代碼出自http://blog.csdn.net/hellogv/,引用請註明出處!
小弟有一部索愛的K508C,在學習J2ME時,發覺它竟是MIDP2.0,因此,就利用它來開始自己的移動開發之旅。  首先,要加入以下這兩句必須的庫引用:import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;  最後,小弟給出實現J2ME發簡訊的函數實現(這裡要注意一下,小靈通和手機的號碼格式是不一樣的):
  public boolean SendSMS(String Number,String Message)//Number就是手機號碼,Message就是簡訊的內容  {    char[] Addr;      Addr=Number.toCharArray();     if(Addr[0]=='1'&&Addr[1]=='0'&&Addr[2]=='6')//當是小靈通號碼(106開頭)         destAddr = "sms://"+Number;     else{    //當是手機時       if (Addr[0] != '+')         destAddr = "sms://+" + Number;       if (Addr[0] == '+')         destAddr = "sms://" + Number;     }     boolean result = true;    try{           MessageConnection conn = (MessageConnection)Connector.open(destAddr);           //設定簡訊息類型為文本,簡訊息有文本和二進位兩種類型           TextMessage msg = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);           //設定資訊內容           msg.setAddress(destAddr);           msg.setPayloadText(Message);           //發送           conn.send(msg);           result = true;    }catch(Exception e){           result = false;           //未處理    }    return result;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.