Send short messages by using
For more articles visit: http://blog.csdn.net/mailbomb
In the program, there are generally three ways to send short messages:
1. Use a program to send short messages on the Internet, such as text message services of various websites. In this way, the program sends the information to the gateway server of the carrier, and then sends the information to the mobile phone through the network of the carrier.
2. Connect to the mobile phone through the data cable in the computer, and then send short messages through the mobile phone. This method is implemented by using the AT command. At command of Ericsson mobile phone you can find in the following address: http://mobilityworld.ericsson.com.cn/development/download_hit.asp
3. Send short messages through a program running on the mobile phone. This is exactly how this article is implemented.
To send short messages, you must use the WMA package, which is included in midp2.0 and midp1.0.
Can be implemented through the extension API provided by the vendor, which is basically the same as the WMA class library.
The following is a simple method to send short messages to a specified mobile phone number using WMA. Of course, WMA also provides other methods to send more content.
// Smsutil. Java
Package my. util;
Import javax. Wireless. messaging .*;
Import javax. microedition. Io .*;
/**
* Method for sending text messages
*/
Public class smsutil {
/**
* Send short messages to a specified number
* @ Param content Short Message Content
* @ Param phonenumber: mobile phone number
* @ Return returns true if the message is sent successfully. Otherwise, false is returned.
*/
Public static Boolean send (string content, string phonenumber ){
// Return Value
Boolean result = true;
Try {
// Address
String address = "SMS: //" + phonenumber;
// Establish a connection
Messageconnection conn = (messageconnection) connector. Open (Address );
// Set the Short Message Type to text. The Short Message type can be text or binary.
Textmessage MSG = (textmessage) Conn. newmessage (messageconnection. text_message );
// Set the Information Content
MSG. setpayloadtext (content );
// Send
Conn. Send (MSG );
} Catch (exception e ){
Result = false;
// Not processed
}
Return result;
}
}