Search in sources :

Example 1 with Datagram

use of javax.microedition.io.Datagram in project J2ME-Loader by nikita36078.

the class Connection method newDatagram.

@Override
public Datagram newDatagram(int size, String addr) throws IOException {
    if (!addr.startsWith(PROTOCOL)) {
        throw new IllegalArgumentException("Invalid Protocol " + addr);
    }
    Datagram datagram = new DatagramImpl(size);
    datagram.setAddress(addr);
    return datagram;
}
Also used : Datagram(javax.microedition.io.Datagram)

Example 2 with Datagram

use of javax.microedition.io.Datagram in project J2ME-Loader by nikita36078.

the class Connection method newDatagram.

@Override
public Datagram newDatagram(byte[] buf, int size, String addr) throws IOException {
    if (!addr.startsWith(PROTOCOL)) {
        throw new IllegalArgumentException("Invalid Protocol " + addr);
    }
    Datagram datagram = new DatagramImpl(buf, size);
    datagram.setAddress(addr);
    return datagram;
}
Also used : Datagram(javax.microedition.io.Datagram)

Example 3 with Datagram

use of javax.microedition.io.Datagram 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) {
            }
        }
    }
}
Also used : MessageConnection(javax.wireless.messaging.MessageConnection) Datagram(javax.microedition.io.Datagram) IOException(java.io.IOException) DatagramConnection(javax.microedition.io.DatagramConnection) TextMessage(javax.wireless.messaging.TextMessage) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException)

Aggregations

Datagram (javax.microedition.io.Datagram)3 IOException (java.io.IOException)1 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)1 DatagramConnection (javax.microedition.io.DatagramConnection)1 MediaException (javax.microedition.media.MediaException)1 RecordStoreException (javax.microedition.rms.RecordStoreException)1 MessageConnection (javax.wireless.messaging.MessageConnection)1 TextMessage (javax.wireless.messaging.TextMessage)1