Use J2ME to send mobile phone messages

Source: Internet
Author: User
In a program, there are generally three ways to send short messages:

1, the use of the program on the network to send short messages, such as the major web site SMS business. This approach is to send the information to the operator's gateway server via the program and send it to the phone via the operator's network.

2, in the computer, through the data line to connect to the phone, and then through the mobile phone to send short messages. This is done by using the AT command. Ericsson Mobile at command you can find at the following address: http://mobilityworld.ericsson.com.cn/development/download_hit.asp

3, through the mobile phone to run the program to send short messages. This is the way this article is implemented.



In J2ME, if you want to send short messages, you need to use WMA packs, which are already included in MIDP2.0, MIDP1.0

Can be implemented through vendor-supplied extension APIs, as is the case with WMA's class library.

The following is a simple way to send short messages using WMA to a given cell phone number. Of course WMA also provides other ways to send more content.



Smsutil.java

Package my.util;



Import javax.wireless.messaging.*;

Import javax.microedition.io.*;



/**

* Ways to send text messages

*/



public class smsutil{

/**

* Send SMS to specified number

* @param content text messages

* @param phonenumber Mobile phone number

* Returns True @return sent successfully, otherwise returns false

*/

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

To set the text message type, text message has two types

TextMessage msg = (textmessage) conn.newmessage (messageconnection.text_message);

Set up information content

Msg.setpayloadtext (content);

Send

Conn.send (msg);

}catch (Exception e) {

result = false;

Not processed

}



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.