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 ;}