Send SMS messages using

Source: Internet
Author: User
The following code is from http://blog.csdn.net/hellogv/. for reference, see the source!
The younger brother has a Sony Ericsson k508c. When learning j2-based, he finds that it is midp2.0. Therefore, he uses it to start his mobile development journey. First, add the following library references: Import javax. Wireless. messaging. messageconnection;
Import javax. Wireless. messaging. textmessage; at last, the younger brother provides the function implementation for sending text messages through J2. (note that the cell phone number format is different ):
Public Boolean sendsms (string number, string message) // number indicates the mobile phone number, and message indicates the content of the SMS {char [] ADDR; ADDR = number. tochararray (); If (ADDR [0] = '1' & ADDR [1] = '0' & ADDR [2] = '6 ') // when it is a PHS number (starting with 106) destaddr = "SMS: //" + number; else {// when it is a mobile phone if (ADDR [0]! = '+') Destaddr = "SMS: // +" + number; If (ADDR [0] = '+') destaddr = "SMS: // "+ number;} boolean result = true; try {messageconnection conn = (messageconnection) connector. open (destaddr); // set the Short Message Type to text. Short Messages can be textmessage MSG = (textmessage) Conn. newmessage (messageconnection. text_message); // sets the message content MSG. setaddress (destaddr); MSG. setpayloadtext (Message); // send Conn. send (MSG); Result = true;} catch (exception e) {result = false; // unprocessed} return result ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.