Sei sulla pagina 1di 2

//How to send an sms

import java.io.IOException;

import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;

/** Sends an SMS message */


public class SMSender implements Runnable {
private String smsReceiverPort;
private String message;
private String phoneNumber;

public SMSender(String smsReceiverPort) {


this.smsReceiverPort = smsReceiverPort;
}

public void run() {


StringBuffer addr = new StringBuffer(20);
addr.append("sms://+");
if (phoneNumber.length() == 11)
addr.append("86");// china

addr.append(phoneNumber);
// String address = "sms://+8613641301055";
String address = addr.toString();

MessageConnection smsconn = null;


try {
// Open the message connection.
smsconn = (MessageConnection) Connector.open(address);
// Create the message.
TextMessage txtmessage = (TextMessage) smsconn
.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setAddress(address);// !!
txtmessage.setPayloadText(message);
smsconn.send(txtmessage);
} catch (Exception e) {
e.printStackTrace();
}

if (smsconn != null) {
try {
smsconn.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}

public void send(String message, String phoneNumber) {


this.message = message;
this.phoneNumber = phoneNumber;
Thread t = new Thread(this);
t.start();
}

===================Cptcha=====================
reCAPTCHA: stop spam. read books. close this window
Instructions

Please enter the words you see in the box, in order and separated by a space. Doing so helps
prevent automated programs from abusing this service.
*

If you are not sure what the words are, either enter your best guess or click the reload button
next to the distorted words.
*

Visually impaired users can click the audio button to hear a set of words that can be entered
instead of the visual challenge.
*

Still need help? Contact us

Helping the World One Word at a Time

By entering the words in the box, you are also helping to digitize texts that were written before the
computer age. The words that you see were taken directly from old texts that are being scanned
and stored in digital format in order to preserve them and make them more accessible to the
world. Since some of the words in these texts are difficult for computers to process, we are using
the results of your efforts to help decipher them.

Learn More!

Potrebbero piacerti anche