Send short messages by using

Source: Internet
Author: User

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

Related Article

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.