use of javax.wireless.messaging.TextMessage in project CodenameOne by codenameone.
the class GameCanvasImplementation method sendSMS.
/**
* @inheritDoc
*/
public void sendSMS(final String phoneNumber, final String message) throws IOException {
String address = "sms://" + phoneNumber;
MessageConnection con = null;
try {
con = (MessageConnection) Connector.open(address);
TextMessage txtmessage = (TextMessage) con.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setAddress(address);
txtmessage.setPayloadText(message);
con.send(txtmessage);
} catch (Exception e) {
throw new IOException("failed to send sms " + e.getMessage());
} finally {
if (con != null) {
try {
con.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}
use of javax.wireless.messaging.TextMessage in project CodenameOne by codenameone.
the class BlackBerryImplementation method sendSMS.
public void sendSMS(final String phoneNumber, final String message, boolean i) throws IOException {
// one for GSM
if (!isCDMA()) {
String address = "sms://" + phoneNumber;
MessageConnection con = null;
try {
con = (MessageConnection) Connector.open(address);
TextMessage txtmessage = (TextMessage) con.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setAddress(address);
txtmessage.setPayloadText(message);
con.send(txtmessage);
} catch (Exception e) {
throw new IOException("failed to send sms " + e.getMessage());
} finally {
if (con != null) {
try {
con.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
} else {
DatagramConnection connection = null;
try {
byte[] data = (message).getBytes("UTF-8");
connection = (DatagramConnection) Connector.open("sms://" + phoneNumber);
Datagram dg = connection.newDatagram(connection.getMaximumLength());
dg.setData(data, 0, data.length);
connection.send(dg);
} catch (IOException e) {
throw new IOException("failed to send sms " + e.getMessage());
} finally {
try {
connection.close();
connection = null;
} catch (Exception e) {
}
}
}
}
Aggregations