Send mobile phone short information using J2ME

xiaoxiao2021-03-06  23

Send mobile phone short information using J2ME

More articles please visit: http://blog.9cbs.net/mailbomb

In the program, the way to send a short message is generally three:

1. Use the program to send short information on the network, such as SMS services for major websites. This approach is to send information to the operator's gateway server through the program, and then send it to the mobile phone through the carrier's network.

2. In the computer, connect to the phone through the data cable, then send short information through the phone. This approach is achieved by using the AT command. Ericsson mobile phone AT instructions You can find: http://mobilityworld.ericsson.com.cn/development/download_hit.asp

3. Send short information by running the program running in the phone. This is the way it is implemented herein.

In J2ME, if you want to send a short message, you need to use the WMA package, MIDP2.0 already included, MIDP1.0

The expansion API implementation provided by the manufacturer is basically the same as the WMA class library.

Below is a way to send a short message to the designated mobile phone number to the designated mobile phone number, very simple. Of course, WMA also provides other ways 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 information to the specified number

* @Param Content Short message content

* @Param Phonenumber mobile number

* @return sends successfully returns true, otherwise returns false

* /

Public static boolean send (string content, string phoneenumber) {

//return value

Boolean Result = true;

Try {

//address

String address = "sms: //" phonenumber;

//establish connection

MessageConnection Conn = (MessageConnection) Connector.open (Address);

/ / Set the short message type is text, short message has two types of text and 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;

// Unprocessed

}

Return Result;

}

}

转载请注明原文地址:https://www.9cbs.com/read-68219.html

New Post(0)