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